Ever since the Battle of Karbala, true-believer Shi’ites kept track of a secret line of true Imams descended from one survivor. It was inevitable that someone would emerge to challenge Abbasid power, and to this end, the regime was constantly scanning for candidates to arrest and execute.
The Caliph’s territory was just too large to maintain close control, so it’s not surprising that the first serious challenge to Abbasid power came from the frontier. But instead of emerging in Khorasan or Bukhara in the east, it showed up in Tunisia, among the discontented Berbers.
A man named Abdullah al-Mahdi Billah began to preach to the Kutama Berbers that he was the true Imam: a descendant of the secret 7th Imam, Ismail. Here you need to know about a sectarian split:
Ismailis differ from Twelvers (the Iranian majority) in that they all agree on the first six Imams, ending with Mohammed’s great-great-grandson Jafar, but after that they favor different sons of Jafar. Ismail was one of the sons, Musa the other. Musa outlived Jafar, while Ismail was already deceased; but the Ismailis follow a line through Ismail’s son, not through Musa. They also count only one of the grandsons of Mohammed, so their 7th Imam Jafar is the Twelvers’ 6th Imam Jafar. Ismailis are also called Seveners.
Ismaili Imams 8, 9 and 10 had lived furtively in Syria under constant Abbasid threat, but they believed the 10th century was their moment. They sent some missionaries ahead to Morocco, first. Then, traveling as a merchant, the 11th Imam, Abdullah al-Mahdi Billah, came to Morocco and revealed himself publicly.
By claiming descent from Fatima, he claimed both spiritual and secular power. His movement was generally Shi’ite, and more specifically Ismaili; it is historically named the Fatimid Dynasty. All of the Shi’ite Imams are descended from Fatima, Mohammed’s daughter, but this group ended up with it as a historical name.
The Sunni Muslim governors of North Africa put al-Mahdi in prison, but Ismaili supporters in Syria were ready; they sent a rebel army to rescue al-Mahdi and establish his rule in 909. Al-Mahdi’s forces consolidated power and began moving eastward through Algeria.
In 920, the Imam-Caliph moved into a new capital city, Al-Mahdiyah, on the Tunisian coast. Bulgaria and Constantinople quickly enriched the Fatimid Caliph with a bidding war of alliance gifts. (Bulgaria lost.) The Fatimids took control of Sicily, then moved along the African coast into Libya. So far this was bad (the Fatimid towns stopped paying Abbasid taxes), but its psychological effect on Baghdad was minimal. Egypt was the jewel in the Caliph’s crown, and it had been able to stave off invaders from Libya for centuries. Egypt was safe.
But in 969, the Emir of Egypt was defeated by Fatimid forces. To understand how serious this was, we need to realize that Egypt had been almost single-handedly feeding imperial armies for a long time. Losing Egypt meant famine among the troops; it meant sickness, desertion, and general military weakness. Losing Egypt was always the prelude to losing everything.
The Fatimids took Alexandria and pressed into the Nile Delta heartland. They set up their new government in the town of Fustat, near Memphis, then began to build a city on the ruins of old Fort Babylon. One legend suggests that the name “Cairo” was based on the planet Mars, which was high in the sky as they started construction. That was cutting-edge science in 970, of course. Cairo became the capital city of Shi’ite Ismaili fervor, as well as the ruling city of the Fatimids.
Abbasid Baghdad began to lose its regional influence. The Seljuks came closer, while more eastern provinces broke away. Constantinople made a marriage/conversion alliance with the Kievan Rus (basically, Vikings). With the added territory and manpower, the Byzantines were able to conquer Bulgaria and Serbia. Surrounding armies grew, while Baghdad’s withered.
By 1058, a Fatimid army from Egypt marched right into Baghdad to challenge the Abbasid Caliph. The Caliph had only one possible move: he reached out to the nearby Seljuks, who controlled most of the territory north and east of Baghdad. Turkish help was effective, but it came at a price. After that, the de facto ruler in Baghdad was Toghril Bey, the original Seljuk’s grandson. The Abbasids kept their “Caliph” title a little longer, but it didn’t matter.