In 318 B.C., during the sequence of the invasion and sack of Tyre, by Alexander the Great, the Phoenicians founded the Myrtilis or New Tyre. The region became an important trading center frequented by Phoenicians and Carthaginians, thanks to the abundance of river and land routes connecting it to the southern portion of the peninsula. Before the invasion of the Iberian Peninsula, it held commercial importance among these civilizations.
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 Cesar 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 Africans, 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 Alomhad 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 occupation.
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.
In the final decade of the 13th century, or beginning of the 14th century, the dungeons were reconstructed, taking advantage of the older gate and tower of Carocha. This work was supplemented in 1373, by improvements to the dungeons and walls.
Following the signing of the Treaty of Monçao in 1386, the military territories of Mértola, Noudar, Castelo Mendo and Castelo Melhor returned to the possessions of the Portuguese Crown, in exchange for Olivença and Tui. This resulted in further improvements in 1404 to the fortifications.
In the final of the 15th century, the alcalde's residence was constructed, addorsed to the Keep Tower, resulting in much of the demolition of the northwestern battlements. Yet, work persisted in improving the dungeons and walls, although in a diminished capacity. On 25 February 1510, Nuno Velho authored to the King on the state of the fortifications. In 1512, King D. Manuel issued a regal foral., and the castle was recorded by Duarte de Armas (Book of Fortresses in 1509) On 15 October 1513, there is record of a royal letter to pay Francisco de Anzinho 94,260 reis for furnishing lime for the work on the castle.
Until the 18th century, the castle of Mértola continued to function as part of the first defensive line along the frontier with Spain, but began to diminish its military-strategic importance over time, before it was ultimately abandoned. Although important in southern Portugal, the village and castle lost most of its importance during the era of Portuguese maritime expeditions and colonization. Most of the sites decline was reflected in general neglect and lack of conservation, so much that by 1758, the location was in semi-ruin and un-garrisoned.
Between the 19th and 20th century, Mértola's economy was dependent on the exploitation of the mines of Santo Domingo, a major center for cupric pyrite extraction.
On 18 August 1943, by decree 32/973 (Diário do Governo, Série 1, 175), the heritage site was classified as a Imóvel de Interesse Público (Property of Public Interest). On 2 February 1969, a earthquake caused damage to the old fortress.
On 1 June 1992, the property fell into the administration of the Instituto Português do Património Arquitetónico (Portuguese Institute for Architectural Patrimony), under decree-law 106F/92 (Diário da República, Série 1A, 126). A revitalization project began in the 20th century saw the site transformed into a village museum with different areas specializing in different areas related to the castle's history: the keep tower was transformed into an observation deck as well as an interpretative centre presenting Roman, Visigothic Nucleus, Christian and Islamic collections that include one of the best collections Portuguese Islamic art (such as pottery, coins, and jewelry).
The Castle of Mértola is situated in an urban area on the hilltop, implanted in the rocky landscape bisected by the Guadiana River and the Ribeira de Oeiras. Situated nearby is the former Islamic mosque, transformed into the Church of Nossa Senhora da Assunção.
The irregular, rectangular fortress includes four towers: the rectangular keep tower at an angle oriented to the north, two square towers to the south; two rectangular towers to the south; two towers aligned to the principal gate in the east; and a rectangular tower, with circular affect. The "traitors gate" is situated in the northwest wall of the fortifications, following the Keep Tower, protected by barbican. The wall is part of a circuit of battlements, vertical and reinforced by a southwestern tower with large buttress supporting various battlements.
The Keep Tower is 30 metres (98 ft) tall, with soft base and two floors, marked by doorway that opens to staircase addorsed to the southeast walls, consisting of varias friezes along the northwest and marked by machialottans, surmounted by parapets and prismatic merlons and decorated in pyramids. The weapons hall is situated on the first floor, covered with cross-vaulted ceiling. A staircase along the southern wall provides access to the second floor. Alongside the keep tower is a sculpted white marble, relief coat-of-arms of António Rodrigues Bravo, High-Courier (postal official) of the town.
The Carouche Tower, in the southwest, is a cubic 4.7 metres (15 ft) wide, with access from the battlements and covered by terrace, broken by door and window. Its interior, is a covered space with hemispheric copula over pedestals. The towers in the corners flank the main gate, with different volumes (the left is prismatic and the right, semi-circular), that do not extend beyond the height of the battlements.
In the courtyard is a covered cistern with vaulted ceiling over three arches.
The walls encircling the settlement can still be identifiable, defined as a sub rectangular space along the north-to-south axis, with reinforced walls by rectangular towers: a large segment along the north, while a majority of the walls extend along the south flowing from the Carocha Tower, with a part oriented along the Guadiana. To ancient gates, survived by the Misericórdia Gate provides access to the river.