The site of the castle was occupied, successively and uninterrupted by Lusitanians, who constructed a castro to oversee their lands, before being pushed aside by the Romans, who constructed a lookout. By the 7th-8th century, the Visigoths also used the space as a sentry to safeguard their territory.
By the beginning of the 10th century, a small town was founded by Arabs, who reformulated their defences, constructing various dependencies within and outside the walls. Of these constructions, only the cistern in the castle survives their period of occupation. The castle was part of the Moorish defensive line of Silves, during the Almohad Caliphate and era of the Iberian taifas.
In 1242 (or 1246), Aljezur was conquered by knights loyal to Paio Peres Correia. As legend suggests, the conquest of the castle aided by a Moorish woman, who betrayed her fellow countrymen and delivered the citadel into the hands of the knights The Lenda of Maira Aires, also suggests that the castle was taken by Paio Correia on 24 June, on the feast day of the village's patron saint. Its occupation did not result in the partial or total destruction of the castle, although alterations to the fortress occurred in the first decades of its Christian occupation.
Following the 1267 Treaty of Badajoz, the castle and other fortresses along the Algarve were transferred into the dominion of the King Afonso III of Portugalby Alfonso X of Castile. King Denis of Portugal issued a foral (charter) to the region of Aljezur on 12 November 1280, while staying in Estremoz. Thirty years later, the monarch bartered away the Castle of Aljezur and other lands for the town of Almada (1 December 1297).
In 1448, during a visitation by members of the Order of Santiago to the town of Aljezur, they referred to the castle being in a state of abandon, at the same time prohibiting the removal of rock and masonry from the site for other constructions. Further, the report mentioned directions by the Order to reconstruct the walls and the cleaning of the cistern.