from Roman times, but the Muslims built new fortifications and, eventually, a castle to protect it from rival Muslim and Christian states. After the fall of the Caliphate of Córdoba, in 1031, Mértola became an independent taifa state, until it was conquered by the taifa of Seville in 1044-1045. Between 1144 and 1150 the town was again seat of an independent state led by Ibn Qasi, a mystic and skilled military leader who unified Southern Portugal and fought the power of the Almoravides. The independence of the region, however, was soon ended by an invading Almohad army. The most important remnant from the Islamic period in Portugal is Mértola's ancient mosque, built in the second half of the 12th century and later turned into a church, but keeping original architectural characteristics. Reconquista In 1238, in the context of the Reconquista, the town was conquered by Portuguese King Sancho II, putting an end on several centuries of Islamic rule in the Mértola region. The town was donated to the Knights of the Order of St. James, a Military Order that played a vital role in the Christian conquest of Southern Portugal. The seat of the Order was established in Mértola until 1316. From the Reconquista time date most of the castle, including its mighty keep, and a letter of feudal rights (foral), granted in 1254.The economic importance of Mértola and the Guadiana faded after that period. In the 15th-16th centuries, when the Portuguese conquered several cities in the Maghreb, Mértola experienced a brief revival in its economic relevance, supplying Portuguese troops in Northern Africa with cereals. King Manuel I granted a new foral to the town in 1512. Modernity After a long period of economic stagnation, the discovery of copper in the S. Domingos mines led to a new wave of development that would end abruptly in 1965, when the mine was exhausted. In the next decades, the municipality lost much of its population, who emigrated to richer parts of Portugal and other European countries. Starting in the 1980s, a series of archaeological surveys brought to light various remnants of past periods of Mértola, and the town became an important cultural touristic site. Geography Administratively, the municipality is divided into 7 civil parishes (freguesias): Alcaria Ruiva Corte do Pinto Espírito Santo Mértola Santana de Cambas São João dos Caldeireiros São Miguel do Pinheiro, São Pedro de Solis e São Sebastião dos