|Coordinates: 34°15′35″N 6°39′0″W / 34.25972°N 6.65000°W|
|Time zone||UTC+0 (WET)|
|• Summer (DST)||UTC+1 (WEST)|
Mehdya (Arabic: المهدية, romanized: al-Mahdiyā), also Mehdia or Mehedya, is a town in Kénitra Province, Rabat-Salé-Kénitra, Morocco. Previously called al-Ma'mura, it was known as São João da Mamora under 16th century Portuguese occupation, or as La Mamora under 17th century Spanish occupation.
According to the 2004 census, the town has a population of 16,262. It is located on Sebou River (Oued Sebu).
Mehdya was previously called Al-Ma'mura ("the well-populated") or La Mamora in Europe, and was a harbour on the coast of Morocco. Per an ancient account, a colony was founded at the site in the 5th century BCE by the Carthaginians, who called it Thymiaterium.
It was captured by the Portuguese in 1515, and renamed São João da Mamora. Altogether, the Portuguese are documented to have seized 6 Moroccan towns, and built 6 stand-alone fortresses on the Moroccan Atlantic coast, between the river Loukos in the north and the river of Sous in the south. Four of the stand-alone fortresses only had a short duration: Graciosa (1489), Forte de São João de Mamora (pt) (1515), Castelo Real of Mogador (1506–10) and Aguz (1520–25). Two of them were to become permanent urban settlements: Santa Cruz do Cabo de Gué (Agadir, founded in 1505-06), and Mazagan founded in 1514-17. The Portuguese had to abandon most of their settlements between 1541 and 1550, although they were able to keep Ceuta, Tangier and Mazagan.
During the first Anglo-Spanish War, pirates (including English former privateers) had sold captured prizes in Ireland and at the Barbary Coast, where governments struggled to prevent this trade. When peace came in 1604, pirates soon established a pirate haven at Mehdya, a location with the advantage of being near Spain and major trade routes. The Moroccan sultanate tolerated these pirates due to the wealth they brought to the country. However, during summers, Mehdya became less safe as the calmer waters favored the galleys used to suppress piracy; therefore, the coast of Munster was used as a complementary base for piracy.
The only port on the Moroccan coast in the hands of neither the Spanish nor the Moors, Mehdya became the main retreat of Atlantic pirates, important not only as a place to sell their plunder, but also for ship maintenance (including careening). Around 1610, Mehdya was the site of a three-day battle between Dutch and English pirates. The Spanish blockaded Mehdya in 1611, sinking ships and blocking the harbor entrance. In the summer of 1614, the harbor housed at least 30 ships weighing at or above 100 tons, though the bar prevented the passage of ships of above ~300 tons burden.
Mehdya, known as La Mamora, was under Spanish rule between 1614 and 1681. After capturing Larache in 1610, a Spanish fleet under Admiral Luis Fajardo captured Al-Ma'mura during the reign of Mulay Zidan in August 1614, due to the period of anarchy that followed the death of Mulay al-Mansur in 1603. After negotiations with Mulay Zidan, they left a strong garrison of 1,500 men, and called the harbour San Miguel de Ultramar.
The warlord Sidi al-Ayachi led a counter-offensive against Spain, privateering against its shipping, and obtaining the help of the Moriscos and the English. About 1627, he managed to temporarily capture Al-Ma'mura, and add it to his Republic of Salé.
The Spanish retained the city for 67 years, when it was conquered by the Alaouite ruler Moulay Ismaïl. According to tradition, the Bishop of Cadiz had commissioned a statue of Jesus Christ for the church at La Mamora, which was in his diocese. When the Moroccans reoccupied the town in 1681 they took the statue as loot, and later received a ransom from the Spanish for the return of the statue, which was taken to Madrid where it is nowadays venerated under the name of Cristo de Medinaceli.
The new Sultan Mulay Ismail took the city by storm in 1681, and renamed the city al-Mahdiya. (conquest of Mehdya). The iconic Kasbah Mahdiyya was restored and expanded during this period.
In 1795, Mulay Slimane closed the harbour of Mehdya to avoid foreign incursions.
The French occupied Mehdya in 1911.
About 9,000 Allied troops, carried by 19 warships, were landed in Mehdya during Operation Torch in 1942.