A Capital Born of Necessity
When Imam Abdullah al-Mahdi Billah (AS) established Fatimid rule in Ifriqiya in 297 AH / 909 CE, he inherited an old and proud regional capital at Kairouan (al-Qayrawan). Yet Kairouan was the heartland of the established Maliki Sunni scholarly tradition, and the new Ismaili Shia regime — borne to power on the swords of the Berber Kutama tribesmen — found itself ruling a population that was often hostile to its religious claims. The Imam sought a seat of government that would be physically secure, defensible against both internal revolt and external attack, and somewhat removed from the entrenched opposition of the Kairouan establishment.
His answer was to build an entirely new city on the Mediterranean coast. The site chosen lay on a narrow rocky peninsula jutting into the sea south-east of Sousse and south of the later town of Monastir, surrounded by water on three sides with only a thin neck of land connecting it to the mainland. Tradition records that the Imam himself surveyed the ground. The city took his regnal name — al-Mahdiyya, “the city of al-Mahdi” — and was conceived from the outset as a princely fortress-capital rather than an organic urban settlement. For the wider context of this period, see Fatimid North Africa and Fatimid Caliphate.
Foundation and Fortification
Construction of al-Mahdiyya is generally dated to around 303 AH / 916 CE, and the city was formally inaugurated, with the Imam taking up residence, on or about 20 February 921 CE (in the year 308 AH). The defensive engineering was its defining feature. Across the vulnerable landward neck of the peninsula the builders raised an enormous curtain wall — reported in the sources as several metres thick — and dug a great cut or ditch to sever the city from the mainland approach.
The principal land entrance was a monumental fortified gateway later known as the Skifa al-Kahla, the “Dark Vestibule” or “Dark Gate,” a deep vaulted passage through the thickness of the wall that funnelled any attacker into a killing corridor. Much of what stands today reflects later medieval rebuilding, but the gate remains one of the most striking surviving elements of the old fortifications. Within the walls rose the palaces of the Imam and his court, set apart as a royal enclave. The relationship of this architecture to the broader tradition is discussed in Fatimid Architecture.
The Harbour and the Mosque
Two further works anchored al-Mahdiyya’s importance. The first was its harbour: an artificial basin reportedly carved into the solid rock of the shore, protected and capable of sheltering a substantial number of warships. Inheriting a naval tradition from the conquered Aghlabid dynasty, the Fatimids made al-Mahdiyya a forward base for Mediterranean sea power, projecting force toward Sicily, the central Mediterranean, and ultimately Egypt.
The second was the congregational mosque, begun with the city itself around 303 AH / 916 CE. The Great Mosque of al-Mahdiyya is counted among the earliest Fatimid mosques and one of the most significant surviving Fatimid religious monuments in the Maghrib. Its severe, monumental façade and projecting central portal expressed the new dynasty’s claim to authority in stone. The building suffered heavy damage over the centuries and was substantially reconstructed by archaeologists in the twentieth century, so present-day visitors see a careful restoration rather than the untouched original. Within these walls the Fatimid daʿwa proclaimed the imamate of the Ahl al-Bayt — the cause traced in Bohra History.
Trial by Siege: The Revolt of Abu Yazid
Al-Mahdiyya’s fortress character was tested almost to destruction during the reign of the second Imam-Caliph, al-Qaim bi-Amrillah (AS). Beginning in 944 CE, a Kharijite (Ibadi) Berber leader named Abu Yazid — remembered as “the Man on the Donkey” — raised a massive tribal revolt that swept across Ifriqiya and threatened to extinguish Fatimid rule entirely. His forces reached the gates of the capital, and al-Mahdiyya was placed under blockade through much of 945 CE.
It was precisely the defences that the founder had built that saved the dynasty: the peninsula and its walls held, and assaults that reached the palace fortifications were thrown back. The siege eventually collapsed, in large part because the rebel coalition fractured and Abu Yazid’s irregular forces drifted away. The revolt was finally crushed by Imam al-Mansur Billah (AS), who pursued and defeated Abu Yazid in 947 CE. The episode confirmed the wisdom of al-Mahdi’s defensive design even as it exposed the limits of governing from so isolated a stronghold. The reigns of these Imams are treated in Imam Al Qaim Billah and Imam Al Mansur Billah.
From al-Mahdiyya to al-Mansuriyya to Cairo
Al-Mahdiyya’s tenure as the principal Fatimid capital was relatively brief. Imam al-Mansur Billah (AS), in the aftermath of the Abu Yazid war, founded a new royal city near Kairouan named al-Mansuriyya (Sabra al-Mansuriyya), built roughly between 334 and 336 AH / 945–948 CE, and the seat of government shifted there. Al-Mansuriyya was completed under Imam al-Muizz li-Din Allah (AS), who also finished its mosque.
The decisive change came with the Fatimid conquest of Egypt. After his general Jawhar al-Siqilli secured Egypt in 358 AH / 969 CE and laid out a new garrison-city, Imam al-Muizz (AS) transferred the entire centre of the imamate eastward. The court and treasury departed Ifriqiya, and the Imam entered his new Egyptian capital — al-Qahira al-Muizziyya, “the Victorious City of al-Muizz,” today known as Cairo — in 362 AH / 973 CE. This move ended the North African chapter of Fatimid history and inaugurated the great Egyptian era explored in Fatimid Cairo and Imam Al Muizz.
Afterlife of the City
Al-Mahdiyya did not vanish with the eastward move. The Zirid dynasty, governing the Maghrib as Fatimid deputies and later in their own right, returned to al-Mahdiyya as a capital in the mid-eleventh century (around 1057 CE) amid the upheavals of the Banu Hilal migrations. Its harbour and walls kept it strategically important: in 1087 CE a combined Italian fleet from Genoa and Pisa raided the port and burned ships there, an episode often cited as part of the rising Christian naval dominance in the western Mediterranean on the eve of the Crusades. The city would change hands repeatedly in later centuries.
For the Dawoodi Bohra community, al-Mahdiyya holds a particular place as the cradle of the Fatimid state — the first capital from which the Imams of the Ahl al-Bayt governed openly after the period of concealment. Its surviving monuments, above all the Skifa al-Kahla and the Great Mosque, remain tangible links to the founding generation of the Fatimid imamate. The life and significance of its founder are detailed in Imam Al Mahdi Billah.
Note: Some early dates and architectural measurements for al-Mahdiyya vary between the medieval Arabic chronicles and modern scholarship; figures here follow the commonly cited ranges and should be read as approximate where exactness is disputed.