This site was already occupied in the Iron Age, as can be seen from some artifact finds – mostly on display at the Museu Municipal – and section of wall from the period, because it is a strategic location to watch the surrounding land and the river. But the castle also had a defensive system that spread over the surrounding area, consisting of small fortresses and watch towers.
The castle was built during the Islamic period. It was occupied from at least the Almoravid dynasty in the 11th century onwards.
In the 12th and 13th centuries, the Almohad period, the castle underwent major reconstruction work with the aim of resisting the attacks by the Christian armies. The castle walls are robust, with a thickness of 1.50 meters and the watchtowers are solid, rising to a height of 9 meters.
One of the outstanding features is the cistern, a water tank that was used to collect rainwater, built during the Islamic period in the 11th/12th centuries, which was essential for the survival of the castle occupants in the event of danger or enemy siege. It is a rectangular structure, with a roof in the shape of a barrel vault (it is 3.80 meters high in the middle). The structure was made watertight with a 4 cm thick layer of mortar in the inside and outside walls.
Aljezur was taken from the Almohads by forces of the military Order of St. James of the Sword (Ordem de Santiago da Espada) under the command of their master Dom Paio Peres Correia in 1249. The Order exercised control over the whole region, they repaired the castle and constructed the barracks in order to use a military garrison.
The lack of agreement between Dom Afonso X of Castile and Dom Afonso III of Portugal about the sharing of this and other Algarve castles was resolved in 1267 through the Treaty of Badajoz. With Afonso X, the Wise, giving this and other Algarve territory to his grandson Dom Dinis of Portugal, the son of Dom Afonso III and Dona Beatriz.
In 1280, Dom Dinis granted a charter to the settlers of Aljezur. It was established that the king would be responsible for half of the costs of the garrison of the town’s look-out posts, with the other half being provided by the knights of Aljezur.
At the end of the 15th century, peace came to the region and the castle was abandoned.