Abūʾl-Maymūn ʿAbd al-Majīd ibn Muḥammad ibn al-Mustanṣir, better known by his regnal name as al-Ḥāfiẓ li-Dīn Allāh (Arabic: الحافظ لدين الله, lit. 'Keeper of God's Religion'), was the eleventh Fatimid caliph, ruling over Egypt from 1132 to his death in 1149, and the 21st imam of Hafizi Isma'ilism.
Al-Hafiz first rose to power as regent after the death of his cousin, al-Amir bi-Ahkam Allah, in October 1130. Al-Amir had only left an infant son, al-Tayyib, as a possible successor, so al-Hafiz—as the oldest surviving member of the dynasty—became regent. Al-Tayyib was apparently sidelined and possibly killed by the new regime, which was in turn overthrown within a few days by the army under Kutayfat. The latter imprisoned al-Hafiz, and moved to depose the Fatimids and replace Isma'ilism with a personal regime, possibly based on Twelver Shi'ism, with himself as the Hidden Imam's all-powerful vicegerent. Kutayfat's regime was toppled when he was murdered by Fatimid loyalists in December 1131, and al-Hafiz was freed and restored as regent.
On 23 January 1132, al-Hafiz proclaimed himself as the legitimate Isma'ili imam and caliph. While necessary in view of the lack of another heir, the succession was highly irregular, as the Isma'ili imamate had previously only been passed from father to son, by explicit designation (naṣṣ). Al-Hafiz was largely accepted in the Fatimid-ruled territories, but many Isma'ili followers abroad refused to recognize him and regarded the vanished al-Tayyib as their imam, causing the Hafizi–Tayyibi schism in Musta'li Isma'ilism. Even in Egypt, his legitimacy was repeatedly challenged, and his reign was troubled by constant uprisings and power struggles. In an effort to bolster his legitimacy, al-Hafiz was particularly active in the construction and restoration of shrines dedicated to members of the wider Alid family. Al-Hafiz's reign was mostly quiet on the external front. Despite continuing hostilities with the Kingdom of Jerusalem around Ascalon, both powers were preoccupied elsewhere for the most part. The Fatimid court also maintained contact with the Burids in Syria and King Roger II of Sicily, who at this time began his expansion into the former Fatimid domains of Ifriqiya, and adopted many of the practices of the Fatimid court for his own administration.
As ruler, al-Hafiz tried to rein in his over-mighty viziers, with mixed success. He was repeatedly forced to give way to the demands of various military factions, and was ultimately unable to halt the evolution of the vizierate into a de facto sultanate independent of the caliph. Thus al-Hafiz's own son Hasan forced him to name him vizier in 1134, ousting another of the Caliph's sons from the post. Hasan's reign proved tyrannical and he was overthrown by the army in March 1135. The appointment of the Christian Bahram al-Armani to the vizierate after that caused a severe reaction among the Muslim population due to Bahram's pro-Christian policies. This led to another uprising and the appointment of the Sunni Ridwan ibn Walakhshi to the vizierate in 1137. Ridwan not only instituted anti-Christian and anti-Jewish measures, but aimed to overthrow al-Hafiz and replace the Fatimid dynasty with a Sunni regime headed by himself. With the support of the Cairo populace, al-Hafiz thwarted his ambitions and ousted Ridwan in 1139. For the next ten years, the Caliph ruled without a vizier, instead entrusting the administration to a succession of secretaries, with Ibn Masal as leading minister. This period was plagued by uprisings and natural disasters, but al-Hafiz persevered until his death in October 1149. His successors would be reduced to puppets at the hands of powerful viziers, until the end of the Fatimid Caliphate in 1171.
The future al-Hafiz was born as Abd al-Majid at Ascalon in AH 467 (1074/5 CE) or 468 (1075/6). His father was Abu'l-Qasim Muhammad, a son of the reigning Fatimid caliph, al-Mustansir (r. 1036–1094). In later life he was also called by the epithet (kunya) of Abu'l-Maymun. His early life, before he was thrust to the forefront of politics, is almost unknown. As an adult, he is reported to have had a strong mind and mild nature, fond of hoarding things, and to be strongly interested in alchemy and astronomy; he is known to have kept several astronomers in his employ.
On 7 October 1130, Caliph al-Amir bi-Ahkam Allah (r. 1101–1130) was assassinated. He left only a six-month-old son, Abu'l-Qasim al-Tayyib, to succeed him, with no designated regent or serving vizier, as al-Amir had resumed the personal direction of government affairs, instead of entrusting the administration to a potentially dangerously powerful vizier. Al-Amir's murder put a premature end to his attempts to once again concentrate power in the hands of the caliph instead of over-mighty generals and ministers. Given the fragility of succession, it furthermore endangered the very survival of the Fatimid dynasty.
At this time, Abd al-Majid was the oldest surviving male of the dynasty. What happened next appears to have effectively been a coup: two of al-Amir's favourites, Hizar al-Mulk Hazarmard (or Jawarmard) and Barghash, who had influence over the army, allied themselves with Abd al-Majid, to control the government. Abd al-Majid was to become regent, while Hazarmard (winning out over Barghash) would become vizier, and the Armenian Abu'l-Fath Yanis the commander-in-chief and chamberlain to the regent. Hazarmard evidently hoped to establish himself as a quasi-sultan in the style of the all-powerful Armenian vizier Badr al-Jamali and his son al-Afdal Shahanshah while Abd al-Majid may have supported him with the aim of gaining the throne for himself.
As de facto head of state, Abd al-Majid used the title of walī ʿahd al-muslimīn. Previously this was the formal title of the Fatimids' designated successor, but in this context is to be understood as regent. It is unclear, however, in whose name this regency was exercised. Most sources report that even the existence of al-Amir's infant son was concealed, and al-Tayyib disappears completely from the record after that. How the existence of a child whose birth had been accompanied by public celebrations and proclamations, was so effectively concealed is unknown. Modern scholars speculate that al-Tayyib may have died in infancy, possibly even before his father; but at least one contemporary anonymous Syrian source maintains that he was murdered on Abd al-Majid's orders. Instead of al-Tayyib, the new regime maintained that al-Amir had left a pregnant concubine, and that the caliph, having dreamed of his impending death, had declared this unborn child to be a son and his designated (naṣṣ) successor, thus effectively bypassing al-Tayyib. What came of this pregnancy is likewise unclear, as different sources report that the concubine either bore a daughter or that the foetus could not be found, or that al-Hafiz killed the baby soon after.
Whatever the ambitions and intentions of the leaders of the new regime were, they were cut short within a fortnight of al-Amir's death. At the ceremony of the new vizier's investiture, the army, assembled at the Bayn al-Qasrayn square between the caliphal palaces, rose in revolt and demanded the appointment of Kutayfat, the only surviving son of al-Afdal Shahanshah, as vizier. The palace was invaded, Hazarmard was executed and his severed head carried through the streets of Cairo, and on 21 October, Kutayfat was invested as vizier with the titles of his father and grandfather. Formally, Abd al-Majid retained his position of regent, and coins and decrees were issued jointly in his name and that of Kutayfat. In reality, Abd al-Majid was held a prisoner in one of the palace treasuries, guarded by the military commander (and future vizier) Ridwan ibn Walakhshi. Soon, however—possibly after the expected birth of a male heir did not occur—Kutayfat proclaimed the dynasty deposed, and abandoned Isma'ilism as the state religion. He instead proclaimed himself as the vicegerent of a shadowy 'Expected One' (al-Muntaẓar) and 'Rightly-Guided' (al-Mahdī) imam, who was given no name other than the kunya Abu'l-Qasim. The medieval sources explain this as a turn to Twelver Shi'ism, where expectation of the Hidden Imam is a core tenet. The historian Heinz Halm points out that this is nowhere explicitly attested in Kutayfat's own proclamations. Rather, Kutayfat's claim was a convenient political device which not only sidestepped the Fatimid claims to the imamate, but allowed him to rule, in the words of the historian Samuel Miklos Stern, "as a dictator responsible to no one either in theory or practice". Halm also considers that it was Kutayfat who at this point eliminated al-Tayyib.