First Qarmatian invasion of Egypt

In order to stop the Fatimid advance, the Qarmatians, led by al-Hasan al-A'sam, joined in a league with other regional powers, including the Sunni Abbasid caliph in Baghdad.

After defeating and killing the Fatimid commander Ja'far ibn Fallah at Damascus in August 971, the Qarmatians and their Bedouin allies marched south.

After failing to capture Egypt early on and expand into the central lands of the Islamic world held by the Abbasid Caliphate, the Fatimids focused their energy in consolidating their hold on the Maghreb and fighting against the Byzantine Empire on Sicily.

Frequently allied with the perennially restless Bedouin tribes of the Syrian Desert, the Qarmatians raided the caravans of merchants and Hajj pilgrims alike, with the Ikhshidids unable to counter their attacks.

[11][12] In 968, the Qarmatians under al-Hasan al-A'sam even captured Damascus and Ramla, withdrawing only after they secured a ransom and an annual tribute of 300,000 gold dinars from the Ikhshidid governor.

[17] Medieval historians, as well as some of the first modern scholars to examine Isma'ili history, saw a collusion between the Fatimid enterprise in the west and the Qarmatian attacks in the east, but more recent scholarship has disproven this.

[24] As a result, the Qarmatians decided to make common cause with the other regional powers against the Fatimids: Through the mediation of the Abbasid caliph al-Muti', the Qarmatians became the nucleus of a broad anti-Fatimid alliance, comprising the Hamdanid ruler of Mosul, Abu Taghlib, the Buyid ruler Izz al-Dawla, the Bedouin tribes of Banu Kilab and Banu Uqayl, and remnants of the Ikhshidid troops.

[26][27] Upon receiving news of the disaster, Fatimid reinforcements, sent by Jawhar and commanded by Sa'adat ibn Hayyan, withdrew to the coastal town of Jaffa where they fortified themselves.

[28] Al-As'am entered Damascus, where he read the Friday sermon on behalf of al-Muti', denouncing the Fatimids as impostors and their claims to Alid descent as false.

Jawhar had lost much of his army in battle or blockaded in Jaffa, and disposed of only a fraction of his original force that had set out to conquer Egypt and the reinforcements he had received in the meantime.

[28] To protect the newly built city, whose walls were not yet finished, he ordered the excavation of a broad trench just to its north, at the plain of Ayn Shams, between the Nile River and the Muqattam Hills, a distance of c. 10 kilometres (6.2 mi).

A wall was erected behind the trench with only two gates, a large and a small one, which were equipped with iron doors brought from the gardens of the Ikhshidid regent Kafur, whose site was now occupied by Cairo.

[29][36][32] Jawhar took advantage of the Qarmatians' diversion into the Delta to finish his fortifications at Ayn Shams, to raise troops from among the disbanded Ikhshidid soldiery, and to distribute arms to the officials and other civilians who had followed his army from Ifriqiya.

As the sun was setting behind the Fatimid lines, Jawhar opened the large gate and launched a counterattack on the Qarmatian right with his last reserves, Black African slave-soldiers and Berber infantry.

[39][40] In Upper Egypt, the Kilabi leader Abd al-Aziz ibn Ibrahim, formerly a Fatimid ally, maintained his revolt in the name of the Abbasid caliph.

[41] The Fatimid caliph and his court left Ifriqiya in late 972 and arrived in Cairo on 19 June 973, with al-Mu'izz relieving Jawhar from his post as viceroy and taking up the reins of Egypt himself.

[31] Ramla was briefly reoccupied by Ibrahim's troops in May 972,[37] but the Qarmatians soon returned and the Fatimids had to withdraw to Egypt, where Sa'adat ibn Hayyan soon died.

[48] In 992, the declining Qarmatians of Bahrayn, defeated by the Buyids and restricted to their original territory, also formally recognized the political suzerainty of the Fatimid caliphs, while retaining their distinct doctrines.

Map of Early Islamic Syria ( Levant ) and its provinces in the 9th–10th centuries