Occupied since prehistoric times, this region constitutes an important trading center frequented by Phoenicians and Carthaginians, thanks to the existence of river and land routes connecting it to the south of the peninsula. Before the Roman invasion of the Iberian Peninsula, remained the commercial importance. The first historical reference to this settlement is in the Chronicle of the Swabians, the Idácio bishop, narrating an episode dated 440, whose reading can infer the existence of a fortification in place, then called Myrtilis Julia.
Occupied successively by Swabians and Visigoths, from the eighth century met the Muslim domination, responsible for the remodeling of the defenses of this prosperous town. References to this new defensive structure arise at the end of the ninth century, given that between 930 and 1031, the castle was consolidated, becoming one of the strongest in the region. With the fall of the Caliphate of Córdoba (1031), Mértola became an independent kingdom – the Taifa of Mértola – quickly taken up by Al-Mutamid, the Taifa of Seville. A century later, between 1144 and 1151, became independent again (2nd Taifa of Mértola), is likely to have been built new defensive works during the rule of Ibn Qasi (1144-1151). Admittedly, in 1171, already under the rule of the Caliphate Almohad, the fort was enlarged with a tower and, in 1184, with integral turret entrance gate.
At the time of the Reconquest of the Iberian Peninsula Christian, the forces of King Sancho II (1223-1248) invest for the South, following both banks of the river Guadiana been gaining Mértola (on the right bank) and Ayamonte (left) (1238). The first was donated to the Order of Santiago, in the person of their Grand Master, D. Paio Peres Correia (1239). The Order, which already was in charge of the defense of other places south of the country (Alcacer do Sal, Aljustrel, and others), made Mértola its headquarters (chapter) in Portugal, later transferred to the Palmela Castle. In 1254 the town received a charter, raised to town status. Dates from this period the construction of the Homage Tower, whose works were completed in 1292 under the direction of John Fernandes master. This tower and the citadel, were the residence of the Captain-General to the sixteenth century, a time when the structure was gradually abandoned.
Despite the importance of his position, strategic in southern Portugal, the village of Mértola and its castle lost importance from the Portuguese Discoveries. The decline that met from then reflected in the conservation of its walls, so that, in 1758, accused ruin and lacked even the garrison.