Abd Allah al-Mahdi Billah

Abū Muḥammad ʿAbd Allāh ibn al-Ḥusayn (أبو محمد عبد الله بن الحسين; 31 July 874 – 4 March 934), better known by his regnal name al-Mahdī biʾllāh (المهدي بالله, "The Rightly Guided by God"), was the founder of the Isma'ili Fatimid Caliphate, the only major Shi'a caliphate in Islamic history, and the eleventh Imam of the Isma'ili branch of Shi'ism.

He was born as Saʿīd ibn al-Ḥusayn (سعيد بن الحسين) in Askar Mukram to a family that led the secret Isma'ili missionary network, propagating on behalf of the hidden imam, Muhammad ibn Isma'il, who would return as the prophesied Islamic messiah. Orphaned at a young age, he moved to Salamiya, the family's base of operations, where he was adopted by his uncle. In the mid-890s Sa'id succeeded to the leadership of the expanding, which had expanded and gained adherents across the then Muslim world. However, his claims of not merely being a trustee of the hidden imam, but of him and his ancestors holding the imamate itself, led in 899 to a schism in the Isma'ili movement: those who did not recognize his claims split off to become the Qarmatians. The schism was followed by uprisings of pro-Isma'ili Bedouin in Syria in 902–903, launched without his consent by over-eager supporters, who aimed to force him to come forward as the. The Bedouin uprising was suppressed by the Abbasids, but drew the attention of the Abbasid Caliphate's authorities to him, forcing him to abandon Salamiya, and flee first to Ramla, then Fustat in Egypt, and finally Sijilmasa in what is now Morocco. There he remained, living as a merchant, until one of his missionaries, Abu Abdallah al-Shi'i, at the head of the Kutama Berbers overthrew the Aghlabid dynasty of Ifriqiya in 909.

Proclaimed caliph and assuming power in Ifriqiya in January 910, he proclaimed his right to conquer the world in the name of God, but soon fell out with Abu Abdallah and other leading missionaries, who were disappointed that he was not the semi-divine they had been propagating for. Al-Mahdi was able to purge these dissidents, but had to overcome a series of revolts against his authority, either due to opposition to the exactions of the Kutama, the backbone of his power, or due to disillusionment of his followers with his failure to realise the Isma'ili millennialist promises. The state that al-Mahdi built, although underpinned by a messianic ideology, was otherwise conventionally organized, and relied heavily on the personnel of the previous Aghlabid regime and the swords of the Kutama. His expansionist aims achieved only moderate success: two invasions of Egypt were beaten back by the Abbasids, leaving only the Cyrenaica in his hands, while the war with the Byzantine Empire in southern Italy was characterized by raids for plunder and slaves, and did not result in any lasting successes. In the west, his repeated attempts to impose Fatimid rule over the unruly Berbers were challenged not only by Berber rivalries, but also by the Umayyads of al-Andalus, and only secured temporary success. In 921 he moved his court to the newly built fortified palace city of Mahdiya on the Tunisian coast, and spent the rest of his life there. After his death in 934, he was succeeded by his only son, al-Qa'im.

Origin
The origin, identity and early history of the man who founded the Fatimid Caliphate is obscure, and even his name and the place and date of his birth are disputed. According to his official biography, he was born in Askar Mukram, in the Persian province of Khuzistan, on 31 July 874 (12 Shawwal 260 AH), or exactly one year earlier according to a different tradition. Other traditions report that he was born in Baghdad or Kufa in Iraq, or the town of Salamiya, on the western edge of the Syrian Desert. His original name most likely was Sa'id ibn al-Husayn, although in later life he insisted that is real name was Ali, and Sa'id was just a cover name.

His father died in 881/2, and Sa'id was sent to be fostered by his uncle, Abu Ali Muhammad, also known as Abu'l-Shalaghlagh, at Salamiya. On his journey he was joined by Ja'far, a boy who was a few months older than Sa'id and had been reared with him by the same wet-nurse. He became a eunuch and Sa'id's close confidant and chamberlain, and is one of the main sources about his life. A younger brother, known only as Abu Muhammad, did not follow Sa'id to Salamiya.

Early Isma'ilism and Salamiya
Abu'l-Shalaghlagh and Sa'id lived the life of a wealthy merchant household, but in secret the family headed an underground political and religious movement, the Isma'ili ('invitation, calling'). This movement was part of the wider Imami branch of the Shi'a, which held that the leadership of the Muslim community was entrusted by God to a singular, divinely invested and guided imam (leader). The first such imam was Ali ibn Abi Talib, the son-in-law of the Islamic prophet Muhammad and fourth caliph, who according to the Shi'a had been designated as successor by Muhammad, only for this instruction to be ignored by the latter's Companions, who chose Abu Bakr as caliph instead. Shi'a doctrine holds that the imamate was the birthright of Ali's descendants via Fatima, Muhammad's daughter. The Imamis hold that the existence of an imam at all times is a necessity for the world's existence, as the imam is the proof of God, and has the sole authority and divine inspiration to interpret God's revelation; indeed, the imam is considered to be infallible, at least in doctrinal matters. The Imamis especially held that the imamate was the preserve of the Husaynid line of the Alids, where it could only be passed in hereditary succession from father to son via an explicit act of designation (nass) by the previous imam, a choice that is held to have been ordained by God.

In 765, a succession conflict gave rise to the split of the Imami Shi'a, into Isma'ilis and Twelvers: the sixth imam, Ja'far al-Sadiq, died without a clear successor. Al-Sadiq had most likely designated his second son, Isma'il—after whom the Isma'ilis are named—but according to most accounts, Isma'il predeceased his father. Some of al-Sadiq's followers then held that the designation automatically passed on to Isma'il's son, Muhammad, or even that al-Sadiq had designated his grandson while he lived, while others claimed that Isma'il himself was not dead and merely in hiding to escape persecution by the ruling Abbasid Caliphate. Most of al-Sadiq's followers, however, followed Isma'il's younger brother, Musa al-Kazim, and his descendants, becoming the Twelver branch of Shi'ism. According to his followers, Muhammad ibn Isma'il fled the Hejaz and went into concealment (satr), to escape both Abbasid persecution as well as the hostility of his uncle's supporters. He died sometime c. 795 in Khuzistan, after which the fate of the Isma'ili movement is obscure, until it re-emerged in the late ninth century.

During the second half of the ninth century, a wave of millennialist expectations spread in the Muslim world, coinciding with a deep crisis of the Abbasid Caliphate: the Anarchy at Samarra in the 860s, followed by the Zanj Rebellion, enfeebled the Abbasid regime, allowing the rise of breakaway and autonomous regimes in the provinces. Belief in a messiah of Alid descent, the ('the Rightly Guided One') or  ('He Who Arises'), who would usher in the end times, was widespread in the early Islamic world. According to the various traditions heralding his coming, the would rapidly overthrow the Abbasid Caliphate and destroy their capital Baghdad, restore the unity of the Muslims, conquer Constantinople (capital of the Byzantine Empire, the oldest non-Muslim antagonist of the early caliphates), ensure the final triumph of Islam and establish a reign of peace and justice. Thus the leader of the Zanj uprising claimed Alid descent, and proclaimed himself as the, the restorer of heavenly justice to those downtrodden and disenfranchised. As the historian Michael Brett comments, "the Mahdist expectations [...] were focused upon the coming of a more and more mysterious, increasingly supernatural, ultimately eschatological figure in the form of a second Muhammad destined to complete the history of the world". For the Isma'ilis, the expected was none other than their hidden imam, Muhammad ibn Isma'il.

While the imam remained hidden, however, he was represented towards his followers by an agent, living proof of the imam's existence, the. That was the role claimed, according to later sources, by Sa'id's great-grandfather, Abdallah al-Akbar. Leaving his native Askar Mukram, after some wanderings Abdallah al-Akbar had settled in Salamiya, from where he and his successors directed the growth of the. According to later Isma'ili tradition and the reconstruction of modern scholars, Abdallah al-Akbar was in turn succeeded in 827/8 by his son Ahmad, followed by Ahmad's son, Abu'l-Shalaghlagh. It is possible, however, that the origins of the Salamiya-based movement were far more recent than that, and that it had come about only following the start of the anti-Alid and anti-Shi'a policies adopted by the Abbasids under Caliph al-Mutawakkil ((r. 847 – 861)). These policies led not only to a series of Alid/Shi'a uprisings in the decades that followed, but also the increasing persecution of the Twelver imams until the disappearance and supposed "occultation" of the last Twelver imam in 874. It is exactly this period which saw the Isma'ili message of the imminent return of Muhammad ibn Isma'il as the gain traction, aided by dissatisfaction among the Twelver adherents with the political quietism of their leadership, and above all the vacuum left by the occultation, that removed a visible and accessible imam as a source of loyalty and religious guidance.

Despite its activity, this stage of the Isma'ili movement is scarcely covered in later Isma'ili sources, and most of what happened in the last decades of the ninth century, culminating in the "Qarmatian schism" of 899, has been reconstructed and elaborated by a succession of modern scholars—chiefly Vladimir Ivanov, Samuel Miklos Stern, Wilferd Madelung, and Heinz Halm—using mostly anti-Fatimid polemic works. According to this version, Isma'ili s, led by Hamdan Qarmat and his brother-in-law Abdan, spread their network of agents to the area around Kufa in the late 870s, and from there to Persia and Khurasan, while a particularly important role was played by Yemen, whence the Isma'ili agent Ibn Hawshab sent missionaries to Sindh (al-Haytham, 883/84), Bahrayn (Abu Sa'id al-Jannabi, 899), and Ifriqiya (Abu Abdallah al-Shi'i, 893).

In medieval sources as well as modern accounts building on them, all this activity is attributed to a single unified movement, a "secret revolutionary organization carrying on intensive missionary efforts in many regions of the Muslim world" according to Wilferd Madelung. This was the movement headed by Abu'l-Shalaghlagh at Salamiya. The true head of this movement remained hidden even from the senior missionaries, and a certain Fayruz functioned as chief missionary and 'gateway'  to the hidden leader. Brett however cautions that this "grand conspiracy theory of Fatimid origins" reflects mostly the bias of later sources, pro-Fatimid as well as anti-Fatimid, and that it obscures a reality of multiple, separately evolving millennarian movements that existed at the time, and whose political or doctrinal relation to one another is now difficult to reconstruct. According to Brett, the movement at Salamiya was one of many, and only after the establishment of the Fatimid Caliphate were these movements united into a single coherent network, retrospectively, by Fatimid and anti-Fatimid propaganda alike. Indeed modern scholars point out the existence of independent strands of Isma'ili thought in the eastern regions of the Islamic world, propagated by missionaries like Abu Hatim al-Razi (d. 934/5) in Adharbayjan and Muhammad ibn Ahmad al-Nasafi (d. 943) in Khurasan; it was only later, during the second half of the 10th century, that some of these Isma'ili communities were reconciled to Fatimid leadership, with the official Fatimid doctrine coming to incorporate many of their teachings.

Leadership of the Isma'ili and the Qarmatian schism
Abu'l-Shalaghlagh did not have heirs, as his son and grandchild had reportedly been captured and imprisoned by the Abbasids. Sa'id was thus designated as his successor, and given his uncle's daughter in marriage. Sa'id's only child, Abd al-Rahman, the future caliph al-Qa'im bi-Amr Allah, was born in March or April 893. His brother, Abu Muhammad, apparently went to Taleqan in the Daylam, a region where already Abdallah al-Akbar had lived and preached for a while.

The eunuch Ja'far reports that Abu'l-Shalaghlagh—perhaps encouraged by the rapid progress of the, which was now establishing armed strongholds in preparation of the 's arrival—secretly declared himself to a few senior members of the not as the  for Muhammad ibn Isma'il, but the actual imam; and that he claimed for his nephew Sa'id the title of , and for the latter's infant son Abd al-Rahman the title of. This claim was taken up by Sa'id when he succeeded his uncle, although later Fatimid doctrine insisted that Sa'id's father, al-Husayn, had been a hidden imam in succession to Ahmad ibn Abdallah al-Akbar, rather than Abu'l-Shalaghlagh; the latter in turn is accused in these works of trying to usurp the position of Sa'id. Various genealogies were later put forth by the Fatimids and their followers to justify their claim to the imamate, generating a heated controversy that lasts until the present day. In the most common version, Abdallah al-Akbar was proclaimed to be the son of Muhammad ibn Isma'il, but even in pro-Isma'ili sources, the succession line and names of the hidden imams who supposedly preceded Sa'id are not the same, partly due to the Isma'ili practice of using codenames and hiding their identity to avoid persecution. Anti-Isma'ili Sunni and Twelver Shi'a sources naturally rejected the claim of Fatimid descent from Ali ibn Abi Talib altogether and considered them as impostors, some even claiming they were of Jewish descent. The situation is further complicated by the use of the title, until then a synonym for the , for Sa'id's son. This has led to claims, already in medieval times, that whereas Abd al-Rahman was a genuine imam, Sa'id descended from a line of s and was neither Abd al-Rahman's father nor a legitimate imam, but merely a usurping steward.

Abu'l-Shalaghlagh died sometime after 893, and Sa'id became the head of the. In 899, the letters being sent to the senior missionaries from Salamiya revealed changes in the official doctrine of the movement. This worried Hamdan Qarmat, who sent his brother-in-law to Salamiya to investigate the matter. It was only there that Abdan learned of the new claim: that the hidden imam was not Muhammad ibn Isma'il, as commonly believed, but Sa'id. Upon learning of this, Hamdan denounced the leadership in Salamiya, gathered the Iraqi s and ordered them to cease the missionary effort. Shortly after he disappeared from his headquarters, and Abdan was assassinated at the instigation of Zakarawayh ibn Mihrawayh, who had apparently remained loyal to Salamiya. These events caused a major split in the Isma'ili movement, between those who recognized Sa'id's claims to the imamate and those who rejected them. The latter are generally known today by the term "Qarmatians", although the original connotation of the name is unclear, and was also applied by non-Isma'ili authors to the supporters of the Fatimids as well. The Isma'ili communities that adhered to the Qarmatian view represented mostly the eastern Islamic world: Iraq, Bahrayn and northern Persia around Rayy, while the communities in Yemen, Sindh, Ifriqiya and possibly Khurasan remained loyal to Salamiya.

Bedouin uprising and flight to Ramla
After his role in the murder of Abdan, Zakarawayh ibn Mihrawayh escaped from Iraq and resumed his missionary efforts among the Bedouin tribes of the eastern Syrian Desert, but with little success. His sons, al-Husayn and Yahya, however, succeeded in converting many members of the tribal group of the Banu Kalb in the northwestern Syrian Desert. Assuming the cover names of ('Man with the Mole') and  ('Master of the She-Camel') respectively, they and their followers adopted the name  ('Fatimids') and rose in revolt in 902. It remains a matter of contention whether Zakarawayh and his sons were followers of Sa'id and acted in his name, as contended by Ivanov and Halm, or unrelated. The account of the contemporary Baghdadi official and historian al-Tabari knows nothing of the Isma'ili leadership at Salamiya, and provides a garbled account of the rebels' belief system, claiming that a certain Faraj ibn Uthman was their mahdi, while the 11th-century pro-Fatimid narrative of al-Naysaburi insists that the revolt was instigated by the three renegade sons of an Isma'ili da'i.

Whatever the truth, the uprising was apparently without the knowledge or authorization of Sa'id, although later Fatimid sources claim that Zakarawayh sent Sa'id's brother to the Bedouin as the representative of the hidden imam and figurehead of the revolt. Indeed, the revolt, whether by over-eager followers or not, placed Sa'id in mortal danger, as it alerted the authorities to the danger posed by militant Isma'ilism and revealed the whereabouts of the leadership of the. It also led to the renewed direct Abbasid military involvement in Syria, which for the last thirty years had been ruled not by Baghdad, but by the autonomous Tulunid dynasty based in Fustat, in Egypt.

While the Bedouin scored their first successes against government troops, Sa'id was informed via pigeon post from his agents in Baghdad that the Abbasid governor of Salamiya had discovered his true identity. Under cover of night, Sa'id left the town, accompanied only by his son, the chief missionary Fayruz, and four slaves. The women of the household, including his mother and two daughters, as well as his niece, were left behind under the protection of the slave Su'luk. The group speedily went south. In three days they passed Homs, Tripoli, Damascus, and Tiberias, until they reached Ramla, where the local governor was secretly an Isma'ili initiate and could protect them. Sa'id and his party had escaped in the nick of time: in Damascus, the caliphal courier with his description and orders for his arrest arrived right after they had left the city, and another courier arrived at Ramla in the same evening that they settled there.

In the meantime, Zakarawayh's sons had made for Salamiya to pay homage to their master, according to pro-Fatimid sources, or because the town had been settled with Hashemite families related to the Abbasid dynasty, as al-Tabari claims. According to the detailed accounts of pro-Fatimid sources, the two brothers initially held Abu Muhammad to be their imam, until the women of the household corrected them. Yahya went on to lay siege to Damascus, while al-Husayn reportedly went to Ramla to meet Sa'id. Although later Fatimid sources are at pains to disassociate Sa'id from the brothers' uprising, Sa'id at that time may have condoned their operations, and even ordered money to be paid to them. After the death of Yahya before Damascus in July 903, al-Husayn abandoned the siege and turned north. He captured Salamiya, Homs, and other towns, and, in the expectation that the would finally come forth, began to establish the institutions of a state: at the mint of Homs, coins were issued on behalf of the yet unnamed, and in the Friday sermon the name of the Abbasid caliph al-Muktafi was dropped in favour of the "Successor, the rightly-guided Heir, the Lord of the Age, the Commander of the Faithful, the Mahdi". Encamped at Salamiya since August 903, the Bedouin apparently expected that Sa'id would return and announce himself. Despite repeated entreaties, however, Sa'id refused to leave the safety of Ramla. Al-Tabari preserves two letters, one sent to the shadowy and one from him, that were captured by Abbasid troops, in which the  is named Abdallah ibn Ahmad ibn Abdallah. If this was indeed Sa'id, he thus had by this time assumed his eventual regnal name, while apparently omitting his father's.

In the end, the Abbasid government sent an army under Muhammad ibn Sulayman al-Katib, which on 29 November 903 routed the 'Fatimid' Bedouin army at the Battle of Hama. Enraged about the apparent abandonment by the supposed divinely-guided imam, al-Husayn turned against him: the residence at Salamiya was destroyed, and all family members and servants encountered there executed. Sa'id's women, however, were rescued by Sul'uk, who eventually brought them to rejoin his master upon the conquest of Ifriqiya. This atrocity, along with the failure of the uprising, led later Fatimid historians to try and excise Sa'id's relationship with the sons of Zakarawayh in what the historian Heinz Halm calls an act of damnatio memoriae. Al-Husayn himself was captured shortly after, and under torture revealed what he knew about the leader of the Isma'ili movement. Zakarawayh himself remained at large, and in 906 tried to revive the uprising in Iraq in a movement that, according to historian Farhad Daftary, now "acquired the characteristics of dissident Qarmatism". This revolt too was defeated in 907 by Abbasid forces, and Zakarawayh was captured and died of his wounds shortly after.

Flight to Egypt and Sijilmasa
Once again, Sa'id and his entourage had to flee the Abbasid manhunt, making for Tulunid Egypt. Sa'id arrived in Fustat, the capital of Egypt, in early 904, and settled there in the house of a local convert, with the help of the local, Abu Ali. According to the generally considered reliable report of Ibn Hawqal, the latter was none other than Hamdan Qarmat, who had returned to Sa'id's allegiance. Sa'id assumed the guise of a wealthy Hashemite merchant, but local authorities, warned by Baghdad, became suspicious. The loyal eunuch Ja'far was even questioned under torture, but revealed nothing. Sa'id remained in Fustat until January 905, when the Abbasid troops under Muhammad ibn Sulayman al-Katib invaded Egypt and ended the Tulunid regime, bringing the province once again directly under Abbasid control.

To escape the Abbasids, Sa'id was once again forced to flee. His entourage apparently expected him to head to Yemen, where the missionaries Ibn Hawshab and Ibn al-Fadl had conquered most of the country in the name of the Isma'ili imam. Instead, Sa'id resolved to turn west to the Maghreb, much to the surprise and dismay of his followers: while Yemen was part of the civilized Arab world, the Maghreb was wild and uncultured, far from the centres of the Islamic world, politically fractured, and dominated by Berber tribes. Indeed, the chief missionary Fayruz abandoned his master and made for Yemen on his own. The reason for Sa'id's choice is unknown, but the historian Wilferd Madelung suggests that he had doubts about Ibn al-Fadl's loyalty; the latter would indeed eventually renounce his allegiance and declare himself to be the awaited. At the same time, however, the situation in the Maghreb was promising. The Abu Abdallah al-Shi'i had converted the Kutama Berbers to his cause, and by 905 had achieved some first victories against the autonomous Aghlabid dynasty that ruled Ifriqiya (modern Tunisia and eastern Algeria) under nominal Abbasid suzerainty. The later Fatimid apologist, Qadi al-Nu'man, insists that Abu Abdallah had already sent messengers to Salamiya inviting his master to the Maghreb, in an effort to make the decision appear foreordained; but as Halm and Brett have remarked, the episode throws light on the improvised manner in which Sa'id appears to have run his movement.

Sending the trustworthy Ja'far back to Salamiya to dig up the treasures hidden there, Sa'id joined a merchant caravan going west, accompanied by Abu Abdallah's brother, Abu'l-Abbas Muhammad. On the way, the caravan was attacked by Berber tribes, which left Abu'l-Abbas Muhammad wounded, and Sa'id's library and many of his possessions in the hands of their attackers. The party made a stop at Tripoli, where they waited for Ja'far to join them with the recovered treasure. In the meantime, Abu'l-Abbas Muhammad was sent ahead to Kairouan, the Aghlabid capital. Unbeknownst to him, news of Sa'id and his identity as one sought by the Abbasid government had already reached the city, and he was immediately arrested. As a result, once again Sa'id had to alter his plans: instead of crossing the Aghlabid domains and making for the country of the Kutama, he joined another caravan heading west, skirting the southern fringes of Aghlabid territory. He was accompanied only by his son and Ja'far. Pressuring and even bribing the caravan leader to make haste, they eventually arrived in Sijilmasa.

An oasis town in modern eastern Morocco, Sijilmasa was the terminus of several trans-Sahara trade routes, and far from the reach of the Aghlabid emirs. Indeed, its Midrarid ruler, al-Yasa ibn Midrar, like most Berbers, espoused Kharijism, making them foes of the Abbasid caliphs. Posing once again as a wealthy merchant, Sa'id bought a nice residence in the city, and was slowly joined by the rest of his household over the following months. There he remained for the next four years, continuing his mercantile activities which apparently brought him additional wealth, all the while remaining in contact with Abu Abdallah al-Shi'i, who now embarked on the conquest of Ifriqiya. His identity did not remain a secret for too long: the Aghlabid emir, Ziyadat Allah III, informed the Midrarid emir of the true nature of the merchant from the east, but, aided by rich gifts from Sa'id, the emir of Sijilmasa saw no reason to do anything about it. Already before the conquest of the Aghabid emirate was complete, Abu Abdallah sent a troop of Kutama to escort Sa'id to Ifriqiya, but they were waylaid by the Rustamid emir of Tahert and had to turn back.

Establishment of the Fatimid Caliphate
On 18 March 909, the Kutama under the Abu Abdallah decisively defeated the last Aghlabid army at al-Aribus. The next day, Ziyadat Allah III fled his palace city of Raqqada for Egypt, taking many of his treasures with him, but leaving most of his extensive harem behind, and taking care to torch the offices of the land tax department and all fiscal records contained therein. Chaos broke out once this became known, as the palaces were ransacked and any thought of further resistance vanished. A delegation of notables surrendered Kairouan, and on the next day, 25 March 909, Abu Abdallah entered Raqqada and took up residence in the palace of the emir.

Regency of Abu Abdallah al-Shi'i
As his master was still in faraway Sijilmasa, it was up to Abu Abdallah to establish the new Shi'a regime in Ifriqiya. He issued a letter of pardon to the citizens of Kairouan and all former servants of the Aghlabid regime, took stock of the contents of the palaces, installed governors, and ordered changes to the coinage, calls to prayer and the sermon, and official seals to reflect the new regime. The new ruler was not yet named in public; instead, the new formulas used Quranic verses or paraphrases that exalted the Family of Muhammad, the fulfillment of God's promise, the victory of God's truth, and of the Proof of God ((, i.e., the ). Abu'l-Abbas Muhammad, who had escaped from prison and emerged from hiding after his brother's victory, began to spread the Isma'ili doctrine, holding disputations with the local Sunni jurists in the Great Mosque of Kairouan. Abu Abdallah also chose a new chief (judge), in the person of the local Shi'ite Muhammad ibn Umar al-Marwarrudhi.

As soon as his rule was stable enough, on 6 June 909, Abu Aballah set out from Raqqada at the head of a large army, to find his master and hand over power to him. In his stead at Raqqada, he left Abu Zaki Tammam ibn Mu'arik, with his brother Abu'l-Abbas Muhammad as his aide. On the way, Abu Abdallah received the submission of Muhammad ibn Khazar, leader of the nomadic Zenata Berbers, and overthrew the Rustamid imamate at Tahert, installing a Kutama governor there. Learning of the approach of the Kutama army, the emir of Sijilmasa had Sa'id questioned and put under house arrest along with his son, but otherwise treated well. Their servants on the other hand were thrown into prison, and regularly whipped.

Proclamation of al-Mahdi and coming to Ifriqiya
On 26 August 909, the Kutama army reached Sijilmasa, and demanded the release of their captive imam. After brief clashes with the Midrarid troops, Emir al-Yasa fled his city, which was occupied and plundered. Mounted on horseback and dressed in fine clothes, Sa'id and his son were presented to the army, amidst shouts and tears of religious exaltation. On the next day, 27 August, Sa'id was enthroned and acclaimed by the troops. As the historian Michael Brett explains, the occasion had double meaning: on the one hand, it acknowledged Sa'id's caliphate, but on the other, it recognized the Kutama soldiery as 'faithful' or 'friends of God', an elite distinct from the mass of ordinary Muslims.

On 26 August, outside the walls of Sijilmasa, the Imam emerged. He was riding a bay horse and wearing a turban whose cloth trailed over his neck and shoulders, an Egyptian linen shirt and sandals. ... Just then, a voice rang out over the crowds of the Kutama tribesmen: 'O faithful! This is my lord and yours, and the lord of all mankind!' When the Kutama saw their chief, Abu Abd Allah al-Shi'i, dismount from his horse, they followed suit. Al-Shi'i rushed towards the Imam, falling to his knees to kiss the stirrup of the Imam's horse, tears streaming down his face as he wept with joy. Then, he heard the first of Abd Allah al-Mahdi's words, 'Rejoice in the glad-tidings'.

The army remained at Sijilmasa for several weeks, during which delegations offering submission came from across the western Maghreb. The fugitive emir of Sijilmasa was captured, and the Kutama chieftain Ibrahim ibn Ghalib installed as governor. On 12 October, the army began its return march. On the way it relieved Tahert, which in the meantime had come under attack by the Zenata under Ibn Khazar, attacked the tribe of Sadina in its mountain strongholds, and launched an expedition to capture Ibn Khazar, but the latter managed to flee into the desert. The army then turned northeast, and Sa'id visited Ikjan, the original base of Abu Abdallah's mission among the Kutama. There Sa'id arranged the affairs of the Kutama tribes, and took care to gather the treasures that had for years been hoarded in his name.

After twenty days, the army marched on towards Kairouan, where on 4 January 910 the city notables came forth to greet their new ruler. Asked for a renewal of Abu Abdallah's, Sa'id immediately guaranteed their lives, but pointedly did not say anything about their possessions. The new caliph did not enter Kairouan—which he seems never to have visited during his life—and instead rode straight for Raqqada. On the next day, Friday, 5 January 910, in the sermon of the Friday prayer, a manifesto hailing the return of the caliphate to its rightful possessors, the Family of Muhammad, was read, and the name and titles of the new ruler were formally announced: "Abdallah Abu Muhammad, the Imam rightly guided by God, the Commander of the Faithful".

Challenges of a revolutionary regime
The proclamation of al-Mahdi as caliph was the culmination of the decades-long efforts of the Isma'ili, and the first time since the caliphate of Ali ibn Abi Talib (656–661) that a member of the Family of Muhammad governed a major part of the Muslim world. The establishment of the Fatimid Caliphate was part of a wider rise of Shi'a regimes in the 10th-century Muslim world, the so-called "Shi'a Century", which included the Zaydi principalities in Yemen and Tabaristan, the Hamdanids in Syria, and the Buyids in Persia and Iraq.

As Shi'a imams, al-Mahdi and his successors were not only the secular rulers of a state, but concurrently also Shi'a imams, at the head of the still extant and wide-ranging network of the , and thus posed a direct ideological challenge to the Sunni Abbasids for the leadership of the entire Islamic world. Already in his inaugural proclamation, al-Mahdi claimed a mandate to "conquer the world to East and West, in accordance with God's promise, from sinful rebels".

However, in those universalist claims lay the very problem of the new regime; as the historian Hugh Kennedy writes, "the moment when a revolutionary movement achieves power is always of crucial importance", since it has to fulfill its promises to its followers. Al-Mahdi had come to power riding a wave of millennialist and messianic promises, his followers expecting a divinely inspired leader capable of performing miracles. Once in power, however, he would prove to be a mere mortal, and focused more on his legitimist claim on the caliphate as a descendant of Ali, rather than attempting to fulfill the overblown expectations placed on the 'Proof of God' that Abu Abdallah had heralded.

The way that al-Mahdi tried to manage expectations can be seen in the choice of his regnal name: 'Abdallah Abu Muhammad' was the exact reverse of the name of the Islamic prophet Muhammad, and also ensured that his son, now known as Abu'l-Qasim Muhammad rather than Abd al-Rahman, would bear the same name as the Islamic prophet, as had long been prophesied for the : Abu'l-Qasim Muhammad ibn Abdallah. As Halm points out, this allowed al-Mahdi to shift the millennialist expectations of his followers onto his son, buying time. At the same time, however, this also meant that the singular, semi-divine figure of the was now reduced to an adjective in a caliphal title, 'the Imam rightly guided by God' : instead of the promised messiah, al-Mahdi was merely one in a long sequence of imams descending from Ali and Fatima.

Setting up a new administration
A major problem faced by al-Mahdi was the narrow basis of the new regime. The Fatimid dynasty was brought to power by the Kutama, who were, according to Brett, "indispensable", but also "a liability and a threat" to its survival. Halm has described the early Fatimid regime as being little more than a "hegemony of the Kutama". The position of these semi-civilized tribesmen as the chosen warriors of the imam-caliph was greatly resented, not only by the other Berber tribes, but chiefly by the inhabitants of the cities, where the Arabic culture predominated. As Halm writes, the situation was similar to a scenario where, "in the early eighteenth-century North America, the Iroquois, converted to Catholicism by Jesuit missionaries, had overrun the Puritan provinces of New England, installed their chieftains as governors in Boston, Providence and Hartford, and proclaimed a European with dubious credentials as King of England". In Kairouan and the old Aghlabid palace city of al-Qasr al-Qadim, therefore, local Arabs were appointed: al-Hasan ibn Ahmad ibn Abi Khinzir and his brother Khalaf. In the provinces, where Kutama governors were appointed, the first years of Fatimid rule were marked by revolts by the local inhabitants against the arrogance and exactions of the Kutama.

While he appointed the Kutama to garrisons and governorships and gave them rich rewards, in order to administer his new state, al-Mahdi required the expertise of the Arab urban population. As Kennedy remarks, unlike the regimes of later radical Isma'ili groups, al-Mahdi's administration was "surprisingly conventional". For this purpose, al-Mahdi had to take over most of the personnel of the Aghlabid emirs, often men of dubious loyalty, like Ibn al-Qadim. The latter had initially followed Ziyadat Allah III into exile, only to abandon him and return to Ifriqiya with a considerable portion of the former emir's treasure. Al-Mahdi now appointed him to two crucial posts as head of the land tax bureau and of the postal service. The new caliph established a series of new fiscal departments in emulation of Abbasid practice, but notably not a vizierate, instead using the post of secretary to supervise the function of his government. This post was held initially by a holdover from Aghlabid times, Abu'l-Yusr al-Baghdadi, but after his death in January 911 he was replaced by Abu Ja'far Muhammad ibn Ahmad al-Baghdadi, who would continue serving in this capacity under al-Mahdi's successors. After the purge of Abu Abdallah al-Shi'i, the caliph also instituted a new department, the 'bureau of detection' under the supervision of the  Muhammad al-Baghdadi. Unlike contemporary Abbasid practice, which relegated this task to a dedicated department, al-Mahdi was careful to hear and judge petitions for redress against abuse by officials (mazalim) in person.

In another notable department from usual practice, there was no department for the army, as the tribally organized Kutama represented the bulk of the Fatimid military. To complement them, al-Mahdi also took over the surviving Aghlabid slave soldiers, usually of Slavic or Greek  origin, as well as recruiting black Africans. The Arabic settler army of Kairouan was also retained, albeit relegated to secondary status due to their dubious loyalty.

Purge of Abu Abdallah al-Shi'i
The first serious challenge to the new regime arose within the ranks of the very men who had brought it to power, the Kutama chieftains. The prophetic traditions about the, while diffuse, had insisted that his coming would be heralded by celestial signs and portents, that he would be a young man of exceptional beauty, and that he would rapidly and miraculously lead his armies to victory. Not only did al-Mahdi, a 35-year old former merchant accustomed to an easy life, wine, and rich clothing, not match these expectations, but his luxurious lifestyle clashed with the austere doctrines propagated by Abu Abdallah al-Shi'i and hitherto followed by the Kutama. Even Abu Abdallah criticized his master, accusing him of corrupting the Kutama with power, money and luxury and gifts. At the same time, while al-Mahdi reaped the fruits of their sacrifices, the Kutama chieftains saw themselves excluded from the administration, which was staffed with non-Kutama officials, and even with high-ranking members of the Aghlabid government that they had fought against.

As a result, Abu Abdallah became disillusioned with his master. As historian Najam Haider writes, this was a "failure of expectations", as al-Mahdi "did not live up to [Abu Abdallah's] vision of a divinely appointed and inerrant figure". An immediate conflict was averted as Abu Abdallah was called to lead an army west in July 910. During the previous months, Sijilmasa had been lost to the Midrarids, Tahert was once more closely besieged by the Zenata, and an uprising broke out among the Kutama, led by a certain Baban. The latter was quickly subdued by loyalist Kutama, and Abu Abdallah managed to defeat the Zenata near Tubna, relieving Tahert and even reaching the Mediterranean coast at Ténès. He then campaigned against the Zenata and Sadina tribes in modern central Algeria, before returning to Raqqada in the winter of 910/11.

At Ténès, however, a conspiracy had begun among the Kutama chieftains: led by Abu Abdallah, they decided to confront the caliph and put his claims to the test. The sources differ on the details, but the Kutama confronted al-Mahdi in a public audience, demanding that he perform a miracle. Abu Abdallah, his brother Abu'l-Abbas Muhammad, Abu Zaki, and the 'supreme shaykh' Abu Musa Harun openly accused him of being a fraud and an impostor. When Abu Musa Harun was murdered shortly after, the other conspirators decided to assassinate al-Mahdi. Possibly due to the doubts of Abu Abdallah, or because they could not agree on his successor, they delayed their action. Informed of their intentions, al-Mahdi moved first. Commanders whose loyalty was suspect were sent to missions away from the capital, and replaced by loyal ones, so that on 18 February 911, Abu Abdallah and Abu'l-Abbas Muhammad were assassinated by loyal Kutama soldiers in the caliph's own palace. News of the death of Abu Abdallah al-Shi'i spread quickly. Al-Mahdi hesitated for two days, but then executed the remaining Kutama leaders involved in the conspiracy.

According to Brett, who rejects or doubts the early association of Abu Abdallah with a central movement based at Salamiya, al-Mahdi's triumph in the contest with Abu Abdallah meant the takeover of "an apocalyptic movement on behalf of a messiah in waiting, which had germinated at some time after the [disappearance of the Twelver imams in 874], and flourished on the periphery of the Abbasid empire". Brett further suggests that the events of 911, with the questions raised about al-Mahdi's identity and the murder of Abu Abdallah, are the origins for the story of the schism of 899 and the death of the missionary Abdan, via a garbled transmission in later anti-Fatimid sources.

Suppression of antinomianism
The new regime also had to contend with the more extremist tendencies among its own followers. Early Isma'ili doctrine preached that all previous revealed religions—Judaism, Christianity, and Islam itself—and their scriptures were but veils: they imposed outer (zahir) forms and rules that were meant to conceal the inner (batin), true religion as it had been practised in Paradise. The coming of Muhammad ibn Isma'il as the mahdi in the end times would reveal these esoteric truths (haqa'iq) and release mankind from the obligations of religious law (shari'a). Al-Mahdi's modification of Isma'ili doctrine to allow for an indefinite number of imams before the final arrival of the end times changed these expectations, but they continued to be widely held, notably by the Qarmatians and other extremist (ghulat) groups; as Daftary points out, these doctrines and acts like the Qarmatian sack of Mecca in 930 "were also seized upon by Sunni polemicists to accuse all Isma'ilis of libertinism and antinomianism".

As late as 921, al-Mahdi had to take measures against about two hundred of his own Isma'ili followers, who openly flouted Islamic law by eating pork and drinking wine in the month of Ramadan. The arrested, among them several prominent men from different cities, regarded the previous obligations restrictions imposed by religious law as lifted, and some of them even went as far as to regard al-Mahdi as god manifest on earth. This was anathema to al-Mahdi and his nascent regime: as Halm explains, "Antinomianism meant anarchy, and so long as the Kingdom of God had not dawned – and according to the revised doctrine, it had not yet dawned — the beneficent reins of the law could not be dispensed with". Official Fatimid doctrine henceforth insisted on the continued validity of the shari'a and the outer strictures of Islamic law, even for those Isma'ili faithful who had been be initiated into the inner truths; but the latent antinomian tendencies of Isma'ilism would re-emerge in the future, in movements such as the Druze and the Order of Assassins.

Maliki hostility
During the 9th century, Kairouan had become one of the greatest centres of Islamic jurisprudence. Its Sunni jurists adopted a critical stance against the Aghlabid emirs, and ambitious chief qadis played an important, and at times autonomous, political role. Dominated by the conservative Maliki school since the mid-9th century, the city's jurists were from the beginning a major source of opposition to the new Fatimid regime and its practices.

Abu Abdallah and his brother had held disputations with the jurists, trying to win them over to backing the Fatimids' claims of the primacy of Ali and his progeny or the tenets of Isma'ili doctrine, but in vain. During the campaign of Abu Abdallah to Sijilmasa, the people of Kairouan apparently hoped that he would never return. In October/November, two prominent jurists were publicly executed and their corpses drawn through the city as a warning. The letters sent by Abu Abdallah, first from Sijilmasa, and then from Ikjan, about the success of his mission and the imminent arrival of "the Imam, our lord and master, the Mahdi, and his son" were read publicly in Kairouan and sent to all cities of the realm, to discourage opposition. Al-Mahdi also tried to reconcile the Malikis, at least at first, but also did not hesitate to impose Isma'ili ritual practices against their vehement objection; leading to constant tensions between the citizens of Kairouan and the Fatimid governors of the city, who were responsible for their implementation.

For the duration of the Fatimids' rule in Ifriqiya, the Maliki elites rejected Fatimid legitimacy. Maliki authors call them merely "Easterners" or even "Unbelievers", and the caliphs by their first names rather than their regnal titles. Al-Mahdi himself was derisively called by the diminutive form of his first name as Ubayd Allah ('Little Abd Allah'); whence the dynasty is usually labelled in hostile Sunni sources as "Ubaydid". Consequently, al-Mahdi sought and found support among the Malikis' rivals, the minority Hanafi school, especially as many of them claimed to have Shi'a sympathies. Men like the first Fatimid chief qadi, al-Marwarrudhi, and the scholar and later Isma'ili, Ibn al-Haytham, belonged to this group. In contrast to Kairouan, the court in the palace city of Raqqada was dominated by Isma'ilis: it had its own Isma'ili Kutama, and al-Mahdi's companions from the time of his flight served as its chamberlains.

The chief, al-Marwarrudhi, was a particular object of hatred by the Maliki Kairouanis due to his uncompromising stance in persecuting any deviation from Isma'ili precepts. In the end, the many death sentences became too much even for al-Mahdi, who had him executed in 915. His replacement, Muhammad ibn Mahfuz al-Qamudi, was another Ifriqiyan, who lasted in office until his death in 919. His successor was Ishaq ibn Abi'l-Minhal, but he proved too moderate for al-Mahdi and was replaced in October 923 by a more determined and fanatical Isma'ili partisan, Muhammad ibn Imran al-Nafti. As al-Nafti died within a few months of taking office, Ibn Abi'l-Minhal was restored to the post. Another figure accused of tyranny was the governor of Kairouan, Abu Sa'id al-Dayf, appointed in 918. The Kairouanis turned to the heir-apparent, al-Qa'im, for assistance in mediating an audience with al-Mahdi to air their grievances. Isolated instances show that the caliph's spy network, complemented and extended by the Isma'ili da'wa to far beyond the borders of his realm, was active in identifying and eliminating figures who actively opposed the Fatimid regime. On the other hand, according to Halm, the tales in Maliki sources of thousands of martyrs perishing in the dungeons of the caliphal palace are very likely a gross exaggeration: al-Mahdi was willing to tolerate dissent as long as it did not break out into public opposition.

Anti-Kutama riots and the uprising of the anti-
In summer 911, a quarrel between a Kutama soldier and an merchant in the old Aghlabid palace city of al-Qasr al-Qadim led to an uprising in the latter. The revolt, led by men associated with the previous regime, subsided after a few clashes with the Kutama, but after enough time had passed, al-Mahdi launched purges of the uprising's leaders, which encompassed his minister Ibn al-Qadim. This was but the first of many uprisings against the Kutama, however, who quickly became hated. In Tahert, a revolt broke out that killed or drove out the Kutama garrison, and then called the Zenata under Ibn Khazar for aid. A Kutama army defeated the Zenata with heavy losses, and sacked Tahert on 1 October. Its former governor, Dawwas ibn Sawlat al-Lahisi, was recalled to Raqqada and executed. In April 912, another quarrel between the Kutama and a local merchant led to bloody clashes in the streets of Kairouan, in which all Kutama in the city were killed; the sources report 700 dead. When al-Mahdi tried to discover the leaders of this affair to punish them, he was met with silence, and had to content himself with a delegation of city notables seeking his pardon.

This incident rankled with the Kutama, and, coupled with the previous doubts about al-Mahdi, helped spark a new uprising. A young boy, Kadu ibn Mu'arik al-Mawati, was proclaimed as the true, new s were appointed, and a new holy book written. Starting from Ikjan, the original centre of Abu Abdallah's mission, the revolt spread to the cities of Mila and Constantine, while a loyalist army sent against them was thrown back after many of the Kutama in its ranks defected. In response, in April/May 912, al-Mahdi officially proclaimed his son, Abu'l-Qasim Muhammad, as heir-apparent, gave him the regnal name ('He who executes God's command'), and placed him in nominal charge of the army sent to quell the revolt. On 21 June 912, the loyalist army decisively defeated the rebels near Mila. The anti- al-Mawati and the other rebel leaders were soon captured, and prominently featured in al-Qa'im's triumphal entry into Kairouan in autumn.

Foundation of Mahdiya
The anti-Kutama riots in Kairouan and al-Qasr al-Qadim highlighted the vulnerability of the palace city of Raqqada, which was poorly fortified. Already in 912, al-Mahdi began seeking a new, and more defensible, site for his residence.He personally travelled the coast for this purpose, even visiting the ruins of ancient Carthage, before settling on the small peninsula of Jumma. A rocky peninsula of about 1.4 km length and only 175 m wide at its base, it was eminently defensible from a land-based attack, and included an ancient Punic artificial harbour cut into the rock.

Construction began on 11 May 916 with a massive landward wall, whose single gate was considered an engineering masterpiece: the trick of installing the doors on beds of glass, so that a single person could open them, was said to have come from al-Mahdi himself. The new palace city was fortified on the seaward side as well, and included a great congregational mosque—the only Fatimid-era structure to survive to modern times—two palaces, one for the caliph and one for his heir-apparent, and other buildings for the caliphal court and administration. The only weakness of Mahdiya was its lack of natural resources, especially water; large grain stores and cisterns were built for rainwater, but in case of a siege, the city would have to be supplied by sea.

As heavy rainfall damaged the palaces in Raqqada, al-Mahdi expedited the move into the new residence with his court, which took place on 20 February 921, although construction was still ongoing. Mahdiya was palace city, arsenal, treasury, and military stronghold in one; only the Fatimid family and its most loyal members were settled there. The garrison was provided by black African slave troops (Zawila), as well as by Slavic slave soldiers and Kutama. The Zawila and Kutama soldiers lived mostly in the city's suburb outside the landward wall. The Arab jund and its leaders, whose loyalties were suspect, was deliberately excluded.

Death and succession
Al-Mahdi died at Mahdiya on 4 March 934, after a period of illness. Al-Qa'im kept his death secret for a hundred days, before announcing a period of public mourning. As the designated (nass) successor of the imam-caliph, al-Qa'im did not face any opposition. His numerous half-siblings by concubines—six sons and seven daughters—never played an important role, and al-Mahdi had deliberately kept them in the palace, not entrusting them with a gubernatorial or military command. Only once, during al-Qa'im's 928 campaign against the Berbers, when he was out of contact with Mahdiya for several weeks and feared lost, did al-Mahdi allow another son, Abu Ali Ahmad, to play a leading role in public ceremonies. The motivation for this unusual move—whether as a result of palace intrigues or due to a genuine concern that al-Qa'im might be dead—and whether al-Mahdi truly intended to promote Ahmad as an alternative successor, remains unknown. Al-Qa'im rushed back to his father's side and consolidated his position, but the affair left a lasting rift between al-Mahdi and his son. However, in Tripolitania a certain Muhammad ibn Talut claimed to be a son of al-Mahdi and laid claim to the caliphate. He managed to rally a large following among the local Berbers, before his deception was discovered and he was executed by his own followers. Otherwise the transition into the new reign was smooth, with al-Qa'im taking up residence in the caliphal palace of Mahdiya and retaining al-Mahdi's ministers in their duties.

Imperial expansion
Immediately after stabilizing his rule over the former Aghlabid domains, al-Mahdi was virtually obliged to engage in imperial expansion. As Brett puts it, this was ultimately "the goal on which his credibility rested, the conquest of the world to East and West". This meant military operations in three directions at once, against three political and ideological powers that dominated the Mediterranean world: the Muslim "usurpers", the Abbasid Caliphate in the east and the Umayyad Emirate of Córdoba in the west; and the main Christian enemy, the Byzantine Empire, in the north, in Sicily and southern Italy.

East: Cyrenaica and Egypt
Following the consolidation of his rule in Ifriqiya, al-Mahdi's first objective was Egypt, the gateway to Syria and Iraq, the old heartlands of the Islamic world and seat of their Abbasid rivals. The Fatimids hoped for help from their sympathizers in Egypt; not only had al-Mahdi himself stayed at Fustat in 904–905, but the sources record that the local Abbasid governor was forced to execute several people for corresponding with al-Mahdi and his son, al-Qa'im.

Conquest of Tripoli
The first step east was Tripoli, which submitted to the Fatimids following the fall of the Aghlabid emirate. The local Hawwara Berbers quickly came to resent the overbearing behaviour of the Kutama soldiery, as well as the heavy tax demands placed upon them. A first uprising and siege of Tripoli in 910–911 was followed by a general revolt of the Hawwara in summer 912. The Fatimid governor of Tripoli fled, and all Kutama in the city were slaughtered. Al-Qa'im led a combined land and naval expedition, laying siege to Tripoli until it capitulated in June 913. Al-Qa'im left one of the principal Kutama generals, Habasa ibn Yusuf, there, to prepare the further eastward expansion of the Fatimid empire.

Loss of Yemen
Al-Mahdi apparently also entertained hopes of a pincer movement against Egypt from two sides, with the support of his missionaries in the Yemen. It was not to be: Ibn al-Fadl, who had conquered most of Yemen from his base in the south of the country, renounced al-Mahdi and proclaimed himself as the in August 911.

The reasons for this are unclear, but are likely related to the contemporary processes of disillusionment with al-Mahdi in Ifriqiya, and the news of the execution of Abu Abdallah al-Shi'i. Al-Mahdi had also sent a letter to the Yemeni faithful, addressing concerns as to his identity and documenting his supposed genealogy. This letter caused much unease and dissension, for al-Mahdi effectively repudiated the title of 'Proof of God' and the notion of a 'second Muhammad', which had been associated with the until then and in whose name Abu Abdallah had proclaimed his victory. In the same letter, he claimed descent from Ja'far al-Sadiq, the last common imam recognized by Twelvers and Isma'ilis alike, via al-Sadiq's eldest son Abdallah al-Aftah, whom he named as the father of his own great-grandfather, Abdallah al-Akbar. Not only did this contradict all previous Isma'ili propaganda, which emphasized that the legitimate imamate had followed the line of al-Sadiq's younger son Isma'il, but the claimed genealogy was patently false: Abdallah al-Aftah died young, and was commonly known to not have had any offspring. The same letter further upended previous doctrine by emphasizing that though he was the expected, his rule would not bring about the end times, but merely represent another link in a line of imams that was to continue endlessly into the future, thereby contradicting all millennialist expectations vested in his person.

The other Isma'ili in the Yemen, Ibn Hawshab, remained loyal to al-Mahdi, but was forced to capitulate against Ibn al-Fadl's forces, and hand over his son Ja'far as a hostage. Both s died within a few months of each other in 915—Ibn al-Fadl was said to have been poisoned by agents of al-Mahdi posing as physicians—leading to the swift collapse of Isma'ili rule in the Yemen. By 917 the Sunni Yu'firids had completed the reconquest of the country in the name of the Abbasid caliph.

First invasion of Egypt
The first expedition against Egypt was launched on 24 January 914, led by Habasa ibn Yusuf. Advancing along the coast, on 6 February it entered Barqa, the capital of Cyrenaica. There Habasa executed two chieftains of the Mazata tribe, who nine years before had waylaid and robbed al-Mahdi during his journey to Ifriqiya; their sons were also killed, and their womenfolk sold into slavery and their possessions confiscated. Encouraged by this success, on 11 July al-Mahdi sent al-Qa'im with another army east to assume command of the expedition. Disregarding these orders, however, the ambitious Habasa led his forces into Egypt, entering Alexandria on 27 August.

The news of the Fatimid invasion threw Baghdad into a panic. The Abbasid government had paid little attention to the affairs of Ifriqiya and the claims of al-Mahdi—al-Tabari refers to him vaguely as al-Khariji ('the Kharijite') or Ibn al-Basri ('Son of the Basran')—but now urgent inquiries were made as to his origin and intentions. The Fatimid campaign in Egypt ultimately failed. The attempts to cross the Nile at Giza and capture Fustat were beaten back, and reinforcements arrived from Syria under Mu'nis al-Muzaffar in April 915, greatly shoring up the Abbasid position in the country. The Fatimid army was also plagued by indiscipline and a divided command, as al-Qa'im fell out with Habasa. The latter eventually deserted the campaign and returned to Ifriqiya. Alarmed by this, al-Qa'im evacuated Alexandria hastily and without battle, leaving much of his armament and equipment behind, returning to Raqqada in 28 May 915. In his rear, Cyrenaica rose in revolt and overthrew Fatimid control; in Barqa, the entire Kutama garrison was killed.

The expedition's failure rocked the Fatimid regime's very foundation and the belief in the divine mission of the imam-caliph was shaken. As a result, discontent arose, particularly among the Kutama sub-tribe of the Malusa, from whom Habasa, now hounded as a criminal, originated. His eventual capture and imprisonment led to the revolt of his brother Ghazwiyya, who had played a crucial role in securing al-Mahdi's regime up to that point, and who had recently been given charge of the entire Kutama country to the west of Ifriqiya. The revolt was quickly crushed, however, and Ghazwiyya and Habasa were executed. When their heads were brought before al-Mahdi, he is said to have exclaimed "Once did these heads enclose the East and West; and now they are contained within this basket!".

Second invasion of Egypt
Al-Mahdi immediately began preparations for a second assault on Egypt, starting with the recapture of Cyrenaica. This was accomplished with the surrender of Barqa after an 18-month siege, in April 917. The expedition against Egypt began on 5 April 919, when al-Qa'im, placed in sole command of the campaign, set out from Raqqada. Although Alexandria's Abbasid garrison had been reinforced, it was abandoned without battle upon the arrival of the Fatimid army. Having already acknowledged Fatimid sovereignty during the first invasion and hence now considered in revolt, the city was sacked by the Fatimid troops.

Once again, the Abbasids concentrated at defending the Nile crossing at Giza. Al-Qa'im did not move against Giza, however, giving time for Abbasid reinforcements under Mu'nis al-Muzaffar to arrive. On 12 March 920, the Fatimid invasion fleet was destroyed by the Abbasid admiral Thamal al-Dulafi, crippling the invaders. Pressed for supplies, al-Qa'im repeated his manoeuvre of 914, occupying the Fayyum Oasis. Fatimid troops also succeeded in occupying much of Upper Egypt, cutting off the grain supply to Fustat.

For an entire year after that, both sides avoided open conflict, and engaged rather in a diplomatic and propaganda battle. Mu'nis offered promises of safe-conduct as well as recognition of the Fatimids as autonomous rulers of Ifriqiya in the style of the Aghlabids, if al-Qa'im and his father submitted to the Abbasid caliph. Al-Qa'im rejected these overtures, reiterating the Fatimid claims to universal dominion as the rightful heirs of Muhammad. He also sent letters to Fustat urging the Egyptians to rise in revolt, and to the two holy cities of Islam, Mecca and Medina, demanding recognition of the Fatimid claims to sovereignty over the Islamic world.

Finally, in late spring 921, the Abbasids launched their attack, capturing Alexandria and then moving onto Fayyum. Cut off in the oasis, al-Qa'im was forced to abandon all his heavy equipment, and with his army crossed the desert to Barqa.

Raids into Egypt and relations with the Qarmatians
For a few years, the Fatimids continued to launch raids from Barqa into Egypt: in 922/23 and 928, Fatimid troops fought Abbasid troops at Dhat al-Himam, some 60 km west of Alexandria. In 923/24, the Fatimid commander Masrur ibn Sulayman ibn Kafi raided one of the oases of the Western Desert (likely Dakhla Oasis), defeated the local governor and occupied the place, before the outbreak of a disease forced him to retreat.

These attacks on Egypt coincided with almost a decade of intensive attacks against the Abbasids by the Qarmatians of Bahrayn, under the leadership of Abu Tahir al-Jannabi; but contrary to the claims by contemporary Arab historians, and the hypotheses put forth by some early 20th-century scholars of Isma'ilism, no coordination between al-Jannabi and al-Mahdi can be established. When the Qarmatians sacked Mecca in 930 and stole the Black Stone, al-Mahdi even sent a letter to Abu Tahir in reproach, and urged him to immediately return of the Black Stone.

Towards the end of his reign, al-Mahdi may have begun organizing a third invasion of Egypt, but it was not launched until after his death, in 936, during a period of turmoil in the province. Like the previous two attempts, it was unsuccessful: it was beaten back by Muhammad ibn Tughj al-Ikhshid, who took over power in Egypt and established his own dynasty there. It was not until 969, when the balance of power had shifted much more decisively in favour of the Fatimids and the Ikhshidid regime had declined, that another invasion was undertaken, leading to the Fatimid conquest of Egypt.

Subduing Berber resistance
The core territories of Fatimid Ifriqiya were the same as in late antique times, when the area had been the Byzantine Exarchate of Africa: Tunisia, northeastern Algeria, and Tripolitania, which had been highly urbanized since antiquity and were used to regular administration and taxation. Outside these areas, the native Berber tribes resisted fiercely any attempts to impose Fatimid rule. From the sedentary farmers of the Nafusa Mountains south of Tripoli, to the inhabitants of the Aurès Mountains in western Tunisia and eastern Algeria—known to Arab authors as the "refuge of all rebels"—to the nomadic Zenata tribesmen of the central Algerian plateau and the settled farmers of Ouarsenis in northwestern Algeria, the mountainous areas generally escaped tight Fatimid control.

In Tripolitania, the Hawwara Berbers were subdued as part of the consolidation of Fatimid rule over Tripoli, and their western neighbours, the Berbers of the Nafusa Mountains, were conquered in a series of campaigns in 922–923 by the Sulayman ibn Kafi al-Ijjani.

An exception was Tahert, which served as a westerly outpost of Fatimid Ifriqiya, located some 300 km from the eastern edge of Ifriqiya proper. Its Fatimid governor, Masala ibn Habus, was a Miknasa Berber, which brought his tribe under the Fatimid banner. The efforts of the Miknasa to spread Isma'ilism in Ouarsenis, on the other hand, failed miserably, as the missionaries were simply killed by the local population. Likewise, in 922, the Kutama commander Fahlun and his men, trying to impose Fatimid rule in the Aurès, including heavy taxation and the dispatch of hostages to Mahdiya, were overwhelmed by the locals and killed in their sleep.

Masala faced the Zenata under their leader Ibn Khazar, who repeatedly tried to wrest control of Tahert from the Fatimids. Masala was killed by his rival in November 924, and was succeeded by his brother, Yasal. Although the latter was able to repel a Zenata attack on Tahert in 925, the defeat of a Fatimid relief army by Ibn Khazar encouraged other Berber tribes in the area to rise in revolt. This forced al-Mahdi to send al-Qa'im to deal with the revolt in person. The heir-apparent set out in April 917, issuing a call to arms not only for the Kutama tribes, but also the Arab and the subdued Berber tribes such as the Hawwara and Ajisa; to ensure the latter's loyalty, the families of their chiefs were sent as hostages to Mahdiya. Al-Mahdi's old slave Su'luk, now known as the chamberlain Ja'far ibn Ubayd, subdued the Kiyana tribe in the Hodna Mountains, whereupon al-Qa'im established a new city, named al-Muhammadiya (modern M'Sila) after himself, to cement Fatimid control over the area. One of the earliest Isma'ili partisans, Ali ibn Hamdun al-Andalusi, was made its first governor. Ziri ibn Manad, the leader of another Berber tribe, the Sanhaja, also offered his submission to al-Qa'im at this time.

Al-Qa'im then entered the Zenata lands in the Zab Mountains, denying them food and pasture, and launching a pursuit of Ibn Khazar. Conditions were hard: uninterrupted rainfall for over a month cut off communications with Mahdiya, where the court feared that the entire expedition was lost. Although Ibn Khazar managed again and again to escape his hunters, in March 928 al-Qa'im sacked the Zenata capital, Zabraqa. The victorious army then returned to Tahert and thence Ifriqiya, being given a triumphal reception at Mahdiya in November 928. His victory dispatch prompted the circulation of a poem, where the al-Qa'im announces himself as the "Son of the Messenger of God" who is about to "roam throughout God's earth...to Egypt and Iraq, and afterwards I shall concern myself with Baghdad".

Despite this success, Fatimid rule over the remote areas of the Maghreb was fragile. Even in Tahert, the local population felt at liberty to nominate their own governor, Masala's son Ali, when Yasal died in 931. Al-Mahdi hat to send a military expedition to the city to install his preferred candidate, Yasal's son Hamid.

Rivalry with Córdoba
Apart from the Abbasids, al-Mahdi faced a major Muslim rival closer to Ifriqiya, in the form of the Umayyads of Córdoba, rulers of al-Andalus (Islamic Spain). However, the confrontation between the two major Islamic powers of the western Mediterranean took place mostly via propaganda and proxies, rather than direct conflict. At the time of al-Mahdi's accession, the Umayyad emirate was plagued by internal dissension, notably the uprising of Ibn Hafsun, who in his conflict with Emir Abdallah ((r. 888 – 912)) pledged his allegiance to al-Mahdi. Al-Mahdi sent robes of honour and two Isma'ili s to the rebel leader, in whose territories the Friday sermon was read in the name of the Fatimid caliph.

Al-Mahdi's campaigns in the western Maghreb, in what is now Morocco, were in part meant to "spread fear on the threshold of the Iberian Peninsula", according to historian Farhat Dachraoui, but the restiveness of the Berber tribes limited the ability of the Fatimid ruler to project power beyond Tahert and seriously contemplate an invasion of al-Andalus. Nevertheless, the Fatimid threat was taken seriously by the Umayyad emir Abd al-Rahman III ((r. 912 – 961)), who reinforced his fleet and established patrols along his southern coasts as one of his first measures upon his accession. During the first two decades of his rule, Abd al-Rahman was occupied with suppressing revolts, most notably that of Ibn Hafsun; but as his power grew, in 927 an Umayyad fleet captured Melilla, establishing it as a military base in the Moroccan coast, followed by Ceuta in 931. Abd al-Rahman also entered into an alliance with Ibn Khazar, recognizing him as the 'paramount emir of the Zenata' and sending him frequent gifts, in exchange for the Berber leader's recognizing Umayyad suzerainty. Finally, once he had secured his own position in al-Andalus, in 929 Abd al-Rahman III claimed the title of caliph for himself, establishing the Caliphate of Córdoba, in a direct challenge to al-Mahdi's pretensions, both temporal and religious.

Attempts to conquer Morocco
In June 917, a Fatimid expedition under Masala ibn Habus sacked the coastal town of Nakur (modern Al Hoceima), the seat of a small emirate. Its ruler was killed, but his sons fled to Malaga on the Spanish coast. Once Masala withdrew his army, however, the exiled princes of Nakur returned with the backing of Emir Abd al-Rahman III, and in a single night managed to overthrow the Fatimid garrison of the town. In exchange, Nakur's new emir became a vassal of the Emir of Córdoba.

Next Masala moved against the domains of the Idrisid dynasty, an Alid clan that ruled over what is now northern and central Morocco. At the time, Idrisid rule over Morocco had fractured into various local principalities, led by competing lines of the dynasty that were fighting each other as well as local rivals. Masala forced the Idrisid ruler of Fes, Yahya IV, to acknowledge Fatimid suzerainty and pay tribute. Yahya's authority was limited to Fes and its environs, while the rest of the country was given to the governorship of Masala's cousin, Musa ibn Abi'l-Afiya.

Masala returned to Morocco in 921, forcing the emir of Nakur to abandon his capital without a fight. Influenced by the ambitious Musa ibn Abi'l-Afiya, Masala marched on Fes, deposed Yahya IV, and installed a Fatimid governor in the city. On the return march, Masala once more imposed Fatimid rule over Sijilmasa, installing a pliant Midrarid as a Fatimid vassal.

The Idrisids' response to the appearance of the Fatimids varied. Prior to the Fatimid invasion, the Idrisids appear to have been aligned with the Umayyads of Córdoba. Some Idrisids accepted al-Mahdi's claims to Alid descent and thus tended to side with the Fatimids, while others resisted Fatimid expansion and turned to the Umayyads of Córdoba for support. One of the latter, al-Hasan al-Hajjam, rose in revolt and recovered Fes. His rule lasted for about two years, before Ibn Abi'l-Afiya retook the city through treachery and had him killed. Ibn Abi'l-Afiya then launched a widespread manhunt against the remaining Idrisids across Morocco, which ended only after local chieftains warned him of the inappropriateness of hunting down descendants of Muhammad. It is likely that at this point, according to the historian Chafik Benchekroun, Ibn Abi'l-Afiya was acting as an independent agent, "without being really neither pro-Fatimid nor pro-Umayyad". In 929/30, Ibn Abi'l-Afiya brutally sacked Nakur and extended his rule over the coast around the mouth of the Moulouya River. Another expedition against Ibn Khazar failed to capture the Zenata chieftain.

Then, in 931/2, Ibn Abi'l-Afiya defected to Abd al-Rahman III. As Halm writes, "with this, Fatimid rule over the far west collapsed with one blow", and the territories held by Ibn Abi'l-Afiya and Ibn Khazar became an Umayyad protectorate. The governor of Tahert, Hamid ibn Yasal, was immediately sent west to restore Fatimid control. He managed to defeat Ibn Abi'l-Afiya and reoccupy Fes, but this was ephemeral: shortly after the Fatimid troops left the city, it was lost again, and Hamid was imprisoned at Mahdiya for his failure. Ibn Abi'l-Afiya returned to Umayyad allegiance, but was soon after killed by the Idrisids.

North: Sicily and Italy
Along with Ifriqiya, al-Mahdi inherited the island of Sicily from the Aghlabids, which had gradually been conquered from the Byzantine Empire during the previous decades. Some Byzantine strongholds remained in the mountainous northeast of the island (the Val Demone), as well as a Byzantine province across the Strait of Messina in Calabria. Sicily was the centre of a perennial war with the Byzantines, which was important from an ideological and propaganda perspective, allowing the Fatimids to "appear as champions of the " against the old Christian enemy of the Muslim world, as the historian Yaacov Lev puts it. At the same time, Lev stresses that the Fatimids were interested more in raiding than outright conquest, that for the Byzantines this was a secondary front, that the fleets involved were small, and that periods of hostility frequently alternated with truces and "a practical policy of modus vivendi".

Revolts in Sicily
In August 910, al-Mahdi sent his governor of Kairouan, al-Hasan ibn Ahmad ibn Abi Khinzir, as the first Fatimid governor to Sicily. Soon he had made himself so unpopular with the Sicilians, apparently due to heavy taxation—Shi'a jurisprudence entailed a 20% income tax known as the 'Fifth' —that they rose in revolt, imprisoned him, and asked for his replacement. His replacement, the elderly Ali ibn Umar al-Balawi, arrived in August 912, but he too was deposed in early 913, and the island rose in revolt under the Aghlabid Ahmad ibn Ziyadat Allah ibn Qurhub, who renounced Fatimid allegiance and received recognition from the Abbasid caliph.

In July 914, the Sicilian fleet, commanded by Ibn Qurhub's younger son Muhammad, raided the coasts of Ifriqiya. At Leptis Minor, the Sicilians caught a Fatimid naval squadron by surprise on 18 July: the Fatimid fleet was torched, and 600 prisoners were made. Among the latter was the former governor of Sicily, Ibn Abi Khinzir, who was executed. The Sicilians defeated a Fatimid army detachment sent to repel them, and proceeded south, sacking Sfax and reaching Tripoli in August 914. Only the presence of al-Qa'im, who was then on his way to invade Egypt, deterred an attack on the city.

In the next year, however, a similar undertaking failed, with the Sicilian fleet being defeated. Some areas, like Agrigento, defected back to the Fatimids. Ibn Qurhub tried to flee to al-Andalus, but was captured and delivered to al-Mahdi. Along with his supporters he was brought to Raqqada, lashed on the tomb of Ibn Abi Khinzir, mutilated, and publicly crucified. The island's capital, Palermo, resisted until March 917. After its capitulation, a Kutama garrison was installed under the governor Salim ibn Asad ibn Abi Rashid. The stronger Fatimid presence allowed Salim to secure relative tranquility for the island over twenty years, remaining in office until another revolt overthrew him in 937.

War with the Byzantines
In August 918, Salim led a night attack on Reggio Calabria, which was captured and sacked. In the following year, however, a truce was signed with Taormina and the other Byzantine strongholds of the Val Demone, possibly so that the Muslim forces could be concentrated on the Italian mainland. There an expedition of 20 ships under Mas'ud al-Fati attacked the fortress of St. Agatha near Reggio in 922/3. In April 924 a major fleet was sent to Sicily, commanded by the chamberlain Ja'far ibn Ubayd. After wintering on the island, he raided Bruzzano near Reggio, before sailing on to sack Oria in Apulia. Over 11,000 prisoners were made, and the local Byzantine commander and bishop surrendered as hostages in surety for the payment of tribute. The chamberlain returned in triumph to Mahdiya in September 925.

At about the same time, al-Mahdi entered into contact with the Bulgarian emperor, Simeon I, who sent envoys to propose a joint attack on the Byzantine capital Constantinople. The Bulgarian ruler suggested that the Bulgarians would invade by land, and the Fatimids come by sea; all spoils would be divided equally, with the Bulgarians keeping Constantinople and the Fatimids gaining the Byzantine territories in Sicily and southern Italy. As a result of a long war with the Byzantines, by 922 the Bulgarians controlled almost the whole Balkan peninsula, but Constantinople remained out of Simeon's reach because he lacked a navy. According to the Byzantine source that reports on these negotiations, al-Mahdi accepted the proposal, but the ship carrying the Bulgarian and Fatimid envoys to Simeon was captured by the Byzantines near the Calabrian coast. When the Byzantine emperor Romanos I learned about the negotiations, the Bulgarians were imprisoned, while the Arab envoys were allowed to return to Mahdiya with rich gifts for the caliph. The Byzantines hastened to renew the 917 peace agreement, including the payment of tribute, and Simeon's death in 927 put an end to his ambitions.

Warfare with the Byzantines resumed in 928, when a fleet was sent to Sicily, led by the governor of Kairouan, Sabir al-Fata. He attacked a locality named ('the caves') in Apulia, and proceeded to sack the cities of Taranto and Otranto. The outbreak of a disease forced them to return to Sicily, but then Sabir led his fleet up the Tyrrhenian Sea, forcing Salerno and Naples to ransom themselves with money and precious brocades. In 929, he defeated the local Byzantine on the Adriatic coast, and sacked Termoli. He returned to Mahdiya on 5 September 930, bringing 18,000 prisoners with him. Encouraged by these successes, al-Mahdi planned a new and larger naval offensive against the Byzantines in Italy, but the arrival of a Byzantine embassy led to the conclusion of another truce in 931/2, which was adhered to until after the caliph's death.

Legacy
The truth of the descent and legitimacy of al-Mahdi's claims has been a subject of intense debate since his appearance on the world stage in the early 900s, and eludes a definite answer. Medieval as well as modern scholars have pointed out the problems in the claims put forth by al-Mahdi or on his behalf by later Isma'ili writers, but his achievement is undeniable: as the orientalist Marius Canard summarized, "Whoever ʿUbayd Allah-Saʿīd may have been, he laid the foundations of the dynasty in North Africa."

Dachraoui attributes to al-Mahdi "tenacity and prudent wisdom" and stresses that, no matter whether al-Mahdi's claims of Alid descent and possession of the imamate were genuine, he was able to successfully establish a new state, end the concealment of the Isma'ili da'wa, and "conduct moderate but firm policies within his provinces, and to wage tireless warfare beyond his frontiers". Brett points out that al-Mahdi's emphasis on constructing a state and dealing with the realities of its governance, left him little time to adapt the Isma'ili doctrine to the new situation and "develop this Caliphate of God into a full-blown creed of the Imamate". This was not achieved until the reign of the fourth Fatimid imam-caliph, al-Mu'izz ((r. 953 – 975)). It was also left to al-Mu'izz to try and woo over the Qarmatians, the Seveners who after the schism of 899 still expected the messianic return of Muhammad ibn Isma'il. In this, the caliph would have some success, as the Iranian communities returned to the Fatimid allegiance, enriching the official Isma'ili doctrine with their intellectual vigor; the Qarmatians of Bahrayn, however, refused to accept the Fatimids as legitimate imams.

Genealogy claimed by al-Mahdi
In a letter sent to the Isma'ili community in Yemen by al-Mahdi Billah, which was recorded by Ja'far ibn Mansur al-Yaman, the following genealogy is given:

denotes imams, regnal names in bold