At the beginning of the Abbasid realm in Baghdad, the Alids faced severe persecution by the ruling party as they were a direct threat to the Abbasid Caliphate. Owing to the political complexities, the forefathers of Imam Abdullah opted to conceal themselves which helped them maintain the Dawa's existence. As a result, these Imams travelled towards the Iranian Plateau to distance themselves from the epicentre of their political difficulties. Al Mahdi's father, Imam al Husain al Mastoor returned in secrecy to Syria and began to control the Dawa's affairs from there in complete concealment. He sent two Da'is of great calibre, Abul Qasim and Abu 'Abdullah Al-Husayn Al-Shi'i to Yemen and North Africa, respectively, to build the foundation for what was to later be the Fatimid Caliphate.
Imam al Husain al Mastoor died soon after the birth of his son, Al Mahdi. A trustworthy system of informers helped Al Mahdi to be updated on developments which were taking place across North Africa which was to be the launching pad of his Empire.
After establishing himself as the first Imam of the Fatimid dynasty, Al Mahdi claimed to have genealogic origins dating as far back as Fatimah, the daughter of the Prophet of Islam, Muhammad, through Husayn, Fatimah's son, and Ismail.
Al Mahdi established his headquarters at Salamiyah in western Syria before later travelling to western North Africa, which at the time was under Aghlabid rule, following the propagandist success of his chief da'i', Abu 'Abdullah Al-Husayn Al-Shi'i. Al-Shi'i, along with laying claim to being the precursor to the Mahdi, was instrumental in sowing the seeds of sedition among the Berber tribes of North Africa, specifically the Kutamah tribe in Algeria.
It was Al-Shi'i's success which was the signal to Al Mahdi to set off from Salamyah disguised as a merchant. In 905 he started proselytising. However, he was captured by the Aghlabid ruler Ziyadat-Allah due to his Ismaili beliefs and thrown into a dungeon in Sijilmasa. In early 909 Al-Shi'i sent a large expedition force to rescue the Mahdi, conquering the Khariji state of Tahert on its way there. After gaining his freedom, Al Mahdi became the leader of the growing state and assumed the position of imam and caliph. Al Mahdi then led the Kutama Berbers who captured the cities of Qairawan and Raqqada. By March 909, the Aghlabid Dynasty had been overthrown and replaced with the Fatimids. As a result, the last stronghold of Sunni Islam in North Africa was removed from the region.
Al-Mahdi established himself at the former Aghlabid residence at Raqqada, Al-Qayrawan (in what is now Tunisia. After that his power grew. At the time of his death he had extended his reign over Morocco and into Egypt.
Al-Mahdi founded the capital of his empire, Al-Mahdiyyah, on the Tunisian coast sixteen miles south-east of Al-Qayrawan, which he named after himself. The city was located on a peninsula on an artificial platform "reclaimed from the sea", as mentioned by the Andalusian geographer Al-Bakri. The Great mosque of Mahdia was built in 916 on the southern side of the peninsula. Al-Mahdi took up residence there in 920.
In 922 the Bulgarian emperor Simeon I sent envoys to al-Mahdi to propose a joined attack on the Byzantine capital Constantinople with the Bulgarians providing a large land army, and the Arabs — a navy. It was proposed that all spoils would be divided equally, the Bulgarians would keep Constantinople and the Fatimids would gain the Byzantine territories in Sicily and South Italy. As a result of the Byzantine–Bulgarian war of 913–927, by 922 the Bulgarians controlled almost the whole Balkan peninsula but Simeon I's main objective to capture Constantinople remained out of his reach because he lacked a navy. Although the Byzantines and the Fatimids had concluded a peace treaty in 914, since 918 the Fatimids had renewed their attacks on the Italian coast.
Al-Mahdi accepted the proposal and sent back his own emissaries to conclude the agreement. On the way home the ship was captured by the Byzantines near the Calabrian coast and the envoys of both countries were sent to Constantinople. When the Byzantine emperor Romanos I learned about the secret negotiations, the Bulgarians were imprisoned, while the Arab envoys were allowed to return to Al-Mahdiyyah with rich gifts for the caliph. The Byzantines then sent their own embassy to North Africa to outbid Simeon I and eventually the Fatimids agreed not to aid Bulgaria.
After his death, Al-Mahdi was succeeded by his son, Abu Al-Qasim Muhammad Al-Qaim, who continued his expansionist policy.
Time line indicating the Imam amongst Shia Imams placed below.