Disputed succession
As the oldest son, Nizar was apparently considered to be his father's most likely successor, as was the custom; indeed, historians often state that Nizar had been his father's designated successor. However, no formal designation of Nizar as heir seems to have taken place by the time of al-Mustansir's death in December 1094.
Al-Maqrizi writes that this was due to the machinations of Badr's son al-Afdal Shahanshah, who had succeeded his father to the vizierate in June 1094. According to al-Maqrizi, a deep-seated enmity existed between al-Afdal and Nizar. An anecdote tells how al-Afdal had once tried to enter the palace on horseback—a privilege reserved for the caliph—whereupon Nizar yelled at him to dismount and called him a "dirty Armenian". Since then, the two had been bitter enemies, with al-Afdal obstructing Nizar's activities and demoting his servants, while at the same time winning the army's commanders over to his cause. Only one of them, the Berber Muhammad ibn Masal al-Lukki, is said to have remained loyal to Nizar, because he had promised to appoint him vizier instead of al-Afdal.
According to al-Maqrizi, al-Afdal pressured al-Mustansir to prevent Nizar's public nomination as heir, and when the caliph died, al-Afdal raised a much younger half-brother of Nizar, al-Musta'li, to the throne and the imamate. Al-Musta'li, who had shortly before married al-Afdal's sister, was completely dependent on al-Afdal for his accession. This made him a compliant figurehead who was unlikely to threaten al-Afdal's recent, and therefore as yet fragile, hold on power.
In order to defend al-Musta'li's succession and counter the claims of Nizar's partisans, al-Mu'stali's son and successor, al-Amir, issued the al-Hidaya al-Amiriyya. This document puts a different spin on the dispersal of the princes: supposedly, they were sent away in order of importance, with those closest to Cairo (and thus the caliph himself) being the highest in rank. Modern historians point out that this was a deliberately misconstrued argument, as the princes were sent away for their protection. According to the historian Paul E. Walker, sending Abu Abdallah to the strong army of Badr al-Jamali was, if anything, an indication of his high importance and of his father's desire to keep him safe. At the same time, the unidentified underage son left in Cairo was clearly not al-Musta'li, who had not even been born yet. Walker identifies the unnamed prince with Abu'l-Qasim Ahmad, whose birth had been publicly announced in 1060. That prince had likely died in the meantime, as the future al-Musta'li, born in 1074, was given the same name.
The al-Hidaya al-Amiriyya and other accounts further assert the legitimacy of al-Musta'li's accession by reporting stories that at the wedding banquet of al-Musta'li, or on his deathbed, al-Mustansir had chosen him as his heir, and that one of al-Mustansir's sisters is said to have been called to him privately and received al-Musta'li's nomination as a bequest. Modern historians, such as Farhad Daftary, believe these stories to be most likely attempts to justify and retroactively legitimize what was in effect a coup d'état by al-Afdal.
However, al-Maqrizi also includes a different narrative that casts doubt on whether al-Afdal's move was really a carefully prepared coup. When al-Afdal summoned three of al-Mustansir's sons—Nizar, Abdallah, and Isma'il, apparently the most prominent among the caliph's progeny—to the palace to do homage to al-Musta'li, who had been seated on the throne, they each refused. Not only did they reject al-Musta'li, but each of them claimed that al-Mustansir had chosen him as his successor. Nizar claimed that he had a written document to this effect. This refusal apparently took al-Afdal completely by surprise. The brothers were allowed to leave the palace; but while Abdallah and Isma'il made for a nearby mosque, Nizar immediately fled Cairo. To add to the confusion, having learned of al-Mustansir's passing, Baraqat, the chief missionary (da'i) of Cairo (the head of the Isma'ili religious establishment) proclaimed Abdallah as caliph with the regnal name al-Muwaffaq. However, al-Afdal soon regained control. Baraqat was arrested (and later executed), Abdallah and Isma'il were placed under surveillance and eventually publicly acknowledged al-Musta'li. A grand assembly of officials was held, which acclaimed al-Musta'li as imam and caliph.