A city already existed at this site during the time of the Phoenicians and Romans, but was destroyed during the Arab conquest of North Africa. Mahdia was founded by the Fatimids under the Caliph Abdallah al-Mahdi in 921 and made the capital city of Ifriqiya, by caliph Abdallah El Fatimi.
It was chosen the capital because of its proximity to the sea, and the promontory on which an important military settlement had been since the time of the Phoenicians. In 1087 the town was attacked by raiding ships from Genoa and Pisa who burned the Muslim fleet in the harbor. This played a critical role in winning control of the Western Mediterranean and allowing the First Crusade to be supplied by sea. The Zirid dynasty had its residence here in the 11th century, but was brought to an end by the Norman conquest of the city in 1148. In 1160 the city comes under Almohad rule.
The role of the capital was taken over by Tunis in the 13th century during the Hafsid Dynasty. Some buildings still exist from the 10th and 11th centuries, such as the Great Mosque and the Casbah, which have helped make the city an important tourist attraction.
Later the city was subject to many raids. In 1390 a French crusader army laid siege to the city but failed to take it. Eventually the city was destroyed and burnt down by the Spanish.
Mahdia was also the site where Khaled Abdelwahhab hid approximately two dozen Jews from the Nazi occupiers during World War II." - in: wikipedia