During the Roman epoch, the settlement was developed, becoming the centre of the mineral extract and agriculture in the Baixo Alentejo region. Mértola was encircled by a wall system that paralleled what remains today, but much grander. The Beja road crossed the walls in the north, and by 44 B.C. Julius Caesar had renamed the town Myrtilis Julia. The first historical reference to this settlement existed in the chronicles of the Swabian bishop, Idácio, who narrated an episode dating to 440 AD, and inferred the existence of this fortified site occupied by Swabians and Visigoths.
It was destroyed and sacked by barbarian hordes, then Muslim Umayyad, who reconstructed the centre for their own necessities, where the name Myrtilis was shortened to Martula. Ibn Qasi was governor of the Taifa of Mértola it is likely that defensive works during his rule (1144–1151) were carried out to the castle.
In the middle of the 12th century, the ribat was constructed on the south tower of the dungeon. During the last third of the 12th century, during the Almohad dynasty, the site was repaired and the walls were constructed to encircle the settlement. During that time, the group of castle buildings were constructed, or reconstructed, that includes the semi-cylindrical tower. In 1171, Abu Háfece, brother of the Emir, ordered the repair and improvements to the fortress tower.
In 1238, during the context of the Reconquista, Mértola was conquered by Sancho II, putting an end to centuries of Islamic reign.
Between 1240/1245 and 1316, the settlement became the seat of the Military Order of Santiago. In 1254, D. Paio Peres Correia issued the regions first foral (charter). The master of the Order, João Fernandes (from the inscription over the entranceway) that ordered the construction of the keep tower in 1292.