Arab rule of the Iberian peninsula forced many Christians to escape from Chaves into the mountains in the northwest. Battles between the Christians and Muslim forces then continued until the 11th century, when Alfonso V of León reconquered the territory. After finally defeating the last vestiges of Moorish influence, he reconstructed, settled and encircled the settlement of Chaves with walls, in addition to establishing a Jewish quarter in the community. It was in the reign of Afonso I of Portugal that it was taken from León and firmly integrated into the Kingdom of Portugal domain (1160). Owing to its geographic location (on Portugal's northern frontier with Spain), King Denis, ordered the construction of a castle to protect the kingdom's border.