Second Qarmatian invasion of Egypt

The Second Qarmatian invasion of Egypt occurred in 974, when Qarmatians of Bahrayn unsuccessfully invaded Egypt, the seat (since 973) of the Fatimid Caliphate. The Qarmatian attack followed upon a failed invasion in 971, which had nevertheless succeeded in evicting the Fatimids from their initial conquests in the Levant. The Fatimid caliph al-Mu'izz was hard put to contain the Qarmatian threat, as his treasury was empty and the populace resentful at the high taxation. His efforts to bring the Qarmatians, who belonged to a different branch of the same Isma'ili sect of Shi'a Islam that had given birth to the Fatimid dynasty, into recognizing his authority as imam, were brusquely rebuffed by the Qarmatian leader, al-Hasan al-A'sam. In late 973, the Alid notable Akhu Muslim entered Egypt and led a rebellion against the Fatimids and their tax collectors, leading other disaffected Alid ashraf to flock to his cause. The main attack was launched in spring 974. The Qarmatian army entered Egypt and occupied the Nile Delta before turning south towards Cairo, but was defeated by the Fatimid heir apparent, Abdallah ibn al-Mu'izz, in battle north of Ayn Shams, close to where the 971 invasion had also been turned back. The Qarmatians retreated to their home territory in Bahrayn, and despite al-A'sam's urgings, reached an accommodation with the Fatimids and largely withdrew from interference in the affairs of the Levant thereafter. The rebellions in Egypt were quickly stamped out by the Fatimid forces. Akhu Muslim managed to evade capture and flee to Arabia, but was poisoned by his former Qarmatian allies. The failure of the Qarmatian invasion opened the way for the Fatimid conquest of Syria over the following years.

Background
In 969, the Fatimid Caliphate, established in Ifriqiya since 909, conquered Egypt from the Ikhshidids. The Fatimid armies were then launched into the Levant, to carry out the jihad against the advancing Byzantine Empire, which had recently captured Antioch, and open the way to Baghdad, the seat of the Fatimids' rivals, the Abbasid caliphs an fulfill their claims to an ecumenical imamate. While the Ikhshidid remnants in the southern Levant were quickly overcome by the Fatimid general Ja'far ibn Fallah in April 970, who captured Ramla and Damascus, the Fatimid advance was stopped by an external enemy, the Qarmatians of Bahrayn.

The Qarmatians had a common origin with the Fatimids, being a dissident branch of the Isma'ili sect of Shi'a Islam that had split away from the mainstream, pro-Fatimid branch in 899. The most notable Qarmatian community was that of Bahrayn, established by the missionary Abu Sa'id al-Jannabi in the 890s. Allied with the local Bedouin tribes of the Banu Kilab and Banu Uqayl, as well as with the Persian Gulf merchants, Abu Sa'id was able to capture the region's capital, Hajr, and in 900 cemented his independence by defeating an Abbasid army sent to recover control of Bahrayn. In the 920s, driven by millennialist expectations of Abu Sa'id's younger son, Abu Tahir al-Jannabi, launched a series of attacks on the declining Abbasid Caliphate that culminated in the Sack of Mecca in 930. The Qarmatians returned to more peaceful relations after 939, sustained through payments of money to abstain from attacking the Hajj caravans. Another wave of Qarmatian raids was launched in the 960s, directed against the Ikhshidid holdings in the Levant. Led by al-Hasan al-A'sam, these raids brought the Qarmatians enormous booty, as well as the promise of an annual tribute of 300,000 gold dinars from the Ikhshidid governor.

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. The Fatimid caliph al-Mu'izz ((r. 953 – 975)) made several attempts to get the scattered Qarmatian communities to recognize his leadership, but although these efforts were successful in some areas, the Qarmatians of Bahrayn persistently refused to do reconcile themselves to Fatimid claims. In reality, the Fatimid conquest of Egypt and their expansion into the Levant ran counter to Qarmatian interests, as it meant the end of the annual tribute; furthermore, the Fatimids' declared intention to restore the safety of the Hajj routes threatened to put an end to the Qarmatians' extortion of the Hajj caravans for protection money as well. As a result, the Qarmatians made 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.

In August 971, the Qarmatian army, commanded by al-A'sam, invaded Syria and destroyed the Fatimid army under Ibn Fallah before Damascus, leading to the collapse of the—widely unpopular—Fatimid rule in the Levant. An invasion of Egypt followed, but instead of making for the capital of Cairo/Fustat, the Qarmatians moved into the Nile Delta to support local anti-Fatimid rebellions, giving Jawhar time to erect fortifications at Ayn Shams, just north of Cairo, and raise additional troops. When the Qarmatians turned south to attack Cairo, they were heavily defeated in battle on 24 December 971 and retreated all the way to Palestine, suffering heavy losses in the process. In the wake of the Qarmatian retreat the Fatimids recaptured Ramla in Palestine in May 972, but only briefly: the Qarmatians returned in summer 972 and the Fatimids had to withdraw to Egypt. On the other hand, the failure of the Qarmatian invasion allowed the Fatimids to stabilize the situation in Egypt, so that in 973, Caliph al-Mu'izz and his court arrived from Ifriqiya and took up residence in Cairo. The rebellions that had broken out in the Delta and Upper Egypt were suppressed, and an attempt of Qarmatian naval assistance to the rebellious city of Tinnis in the Delta was defeated; al-Mu'izz had the prisoners and the decapitated heads of the Qarmatian fallen, and their captured banners, paraded through Cairo before the caliphal lodge on the main gate of the palace.

Renewed revolts and Qarmatian invasion
When al-Mu'izz arrived in Egypt, he found an empty treasury. Despite the considerable income afforded by the tax revenues of Egypt, and the enormous treasure with which Jawhar had set out in 969, the expenditure of stabilizing Fatimid rule, the attempted conquest of Syria and raising forces to combat the Qarmatian invasions, and not least the construction of Cairo as a new capital, had exhausted the country's financial reserves. This forced al-Mu'izz to immediately raise taxes and tighten the tax collection regime; all debt deferrals and exemptions were cancelled. These measures hit particularly hard on the artisan cities of the Nile Delta, which had rebelled again due to high taxation in 969–970, and again during the first Qarmatian invasion, a revolt that had only recently been suppressed with some difficulty. The Caliph's heavy taxation again increased discontent, which began again to break out into revolt as Qarmatian agents infiltrated the country in autumn 973. The most notable of the latter was the Alid Akhu Muslim, scion of the most prominent of the ashraf families of Egypt, who encamped between Asyut and Akhmim, drove out the Fatimid tax officials, and rallied to his cause numerous disaffected members of the ashraf, usually younger sons. Alarmed at the rapid spread of the revolt, which reduced the incoming tax revenue even further, both Caliph al-Mu'izz and the Fatimid chief missionary, Abu Ja'far Nasr, who had befriended Akhu Muslim before the Fatimid conquest, wrote to him to persuade him to abandon the Qarmatian cause, but in vain.

At the same time, in late 973, news of an imminent second invasion arrived in Egypt. To reassure his followers, Caliph al-Mu'izz circulated the story that the Prophet Muhammad and his Companions had appeared in his dream, and that from among their ranks Ali—from whom the Fatimids claimed their descent and legitimacy—had seized his sword Dhu'l-Fiqar and cloven the head of al-A'sam, while the other Companions set upon the other Qarmatian leaders with their swords. In addition, the Caliph sent a letter to al-A'sam, which has survived verbatim as it was included in the material collected by the anti-Fatimid polemicist Akhu Muhsin. In it, al-Mu'izz repeated the claims to the imamate and claimed—falsely—that al-A'sam's forefathers had recognized his ancestors and been their servants. The Qarmatian leader was exhorted to remember their common origins and their common opposition to the Abbasids—whose end was imminent and divinely ordained—and to repent and submit to the Fatimid imam–caliph. Al-Mu'izz gave the Qarmatian commander three choices: to return all booty and pay reparations for the Fatimid soldiers killed so far, to raise the dead back into life, or finally to simply depart with his army, in which case however al-Mu'izz promised to hunt al-A'sam down and bring him to Cairo in a cage. Al-A'sam is said to have sent only a laconic reply: "Your letter, which is very long-winded but not very substantial, has reached us; we are following on its heels". Al-A'sam not only rejected al-Mu'izz's claims, but made the letter public and reaffirmed his opposition to the Fatimids and their claims, launching another invasion of the Fatimid domains in spring 974.

With battle imminent, on 39 March 974, al-Mu'izz reviewed his army and distributed money and weapons to the troops. One of the best Fatimid generals, Rayyan, was sent to the Nile Delta with 4,000 men to the Delta. Rayyan defeated a Qarmatian force at Mahalla, but al-A'sam moved the main Qarmatian army to Bilbays, from where he threatened Cairo. Again the Fatimid caliph was forced to a general call to arms of the entire male population of the capital to confront the Qarmatian advance; not even the members of the court were exempted, apart from Akhu Muslim's brother, Abu Ja'far Muslim, on account of the high esteem al-Mu'izz held for him. On 4 April, the Qarmatian advance guard arrived at Ayn Shams and attacked the fortifications erected by Jawhar in 971. The Fatimids' Berber soldiers repulsed the attack, but during the pursuit they were in turn surprised by a counterattack and suffered heavy losses. This led to the defection of one of the Fatimid commanders, Ali ibn Muhammad al-Khazin, and riots erupting in Fustat. At the same time, news arrived in the capital that Akhu Muslim had defeated a Fatimid army at Akhmim. Fearful of betrayal by the former Ikhshidid commanders now enrolled in his army, on 12 April al-Mu'izz arrested their sons and brought them to Cairo as hostages.

On 27 April, after all available manpower was mustered, al-Mu'izz's son and designated heir Abdallah led the Fatimid army out to confront the Qarmatians at the dry lake bed known as Jubb Umayra or Birkat al-Hajj, just north of Ayn Shams. Al-A'sam divided his army, sending his brother, al-Nu'man, to face the Fatimid advance, while he himself remained on a height dominating the lake bed. Abdallah exploited this mistake, by sending a corps to keep al-A'sam in check, while he destroyed al-Nu'man's force. He then turned on al-A'sam, who was defeated and barely escaped capture. Several eastern Arab sources attribute the Fatimid victory to the defection of the Bedouin chieftain al-Hasan ibn al-Jarrah of the Banu Tayy, who was allegedly bribed with 100,000 gold dinars. While in keeping with Bedouin habits, the impact of the defection, if it really happened, is likely exaggerated by the sources, who are generally hostile to the Fatimids. The Fatimid army took the entire baggage train of the Qarmatians, as well as some 1,500 captives.

On 26 May, the victorious Abdallah made a triumphal entrance into Cairo, accompanied by the most prominent captives on the backs of camels, and several thousand severed heads of the Qarmatian fallen impaled on lances. The fate of the captives varied: former Ikhshidid officers were executed, while the captured Qarmatian commanders were released after a few months, as al-Mu'izz endeavoured to enter into negotiations with them. The Fatimid victory spelled the end of the invasion: al-A'sam retreated back into Syria, but was unable to hold his position there and withdrew to Bahrayn, while in the south, Akhu Muslim dispersed his small army and barely managed to escape capture himself. Hunted by Fatimid agents, he sought refuge among the Qarmatians, but only ended up being poisoned by the latter, who were now engaged in war with the Buyids and conducting peace negotiations with the Fatimids. The remaining rebellions in the Delta were quickly suppressed, followed by Upper Egypt, where resistance took longer to subdue.

Aftermath
Before the year was out, the Fatimids, in pursuit of the Qarmatians recovered Palestine and southern Syria, including Damascus and Tripoli. Qarmatian power shattered and reduced to Bahrayn, and peaceful relations were sealed with the visit of a Qarmatian embassy to Cairo in July 975, where it was received with all due honours. The way was thus opened for the resumption of the Hajj caravans to the holy cities of Mecca and Medina, where the Fatimid caliph's suzerainty was now recognized by the local rulers, an important point of pride and legitimacy in the Fatimids' ideological contest with the Abbasid caliphs. The death of al-Mu'izz in 975 was used as a pretext—very likely with Qarmatian encouragement—by the Sharif of Mecca for the renunciation of Fatimid suzerainty, but the dispatch of an army that cut off the city's grain supply swiftly restored Fatimid control.

In Syria, control of Damascus proved as fragile as before the Qarmatian invasions: the Berber garrison the Fatimids installed proved unruly, and mounting resentment led to riots in the city. In the end the Damascenes turned for assistance to a Turkic mercenary leader, Alptakin, who had fled the turmoils of Buyid Iraq with 300 heavily armored ghulam followers and come to Syria. There he had captured Sidon and Tiberias from the Fatimids, before entering Damascus without resistance. To combat the Fatimids, Alptakin in turn sought the assistance of the Qarmatians, who seized the opportunity to reassert their claims over Palestine. In early 976 the Qarmatians campaigned to Syria, bringing along with them partisans of Alptakin who had been left behind in Iraq. Once again a Qarmatian army occupied Ramla and levied taxes in Palestine, while the Fatimid army withdrew to Jaffa. Further north, Alptakin extended his domain to the coast, but failed to capture more of the Levantine coastal cities.

The new Fatimid caliph, al-Aziz ((r. 975 – 996)), sent Jawhar with an army of 20,000 men into Syria, but they too failed to take Damascus, and suffered from hunger and the cold during the oncoming winter. Al-Hasan al-A'sam again led an army out of Bahrayn that captured Ramla, while Jawhar's depleted army was besieged at Ascalon for 15 months, before agreeing to a humiliating capitulation. Al-Aziz then took matters into his own hand, and campaigned in person in Syria: on 15 August 978, Alptakin was defeated and captured at the Battle of Tawahin, his Turkic and Daylamite soldiers being recruited into the Fatimid army. The Qarmatians, who still occupied Tiberias under al-A'sam's successor, Ja'far, were bought off with an annual tribute of 30,000 gold dinars, in exchange for recognizing a nominal Fatimid suzerainty and leaving Palestine. They never again interfered in the affairs of the Levant. Beyond Damascus, the Fatimids became embroiled in a contest with the Byzantines over control over Hamdanid Aleppo, until a lasting truce was arranged in 1000. 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.