Abū al-Qāsim Muḥammad ibn ʿAbd Allāh (; March/April 893 – 17 May 946), better known by his regnal name al-Qāʾim () or al-Qāʾim bi-Amr Allāh (), was the second caliph of the Fatimid dynasty, ruling in Ifriqiya from 934 to 946. He was the twelfth Isma'ili Imam, succeeding his father Abd Allah al-Mahdi Billah ().
Early life
Origin
The future al-Qa'im was born in the Syrian town of Salamiyah in March or April 893, with the birth name Abd al-Rahman. Abd al-Rahman's father was Sa'id ibn al-Husayn, the future Caliph Abd Allah al-Mahdi Billah. Abd al-Rahman's mother was Sa'id's paternal cousin, the daughter of Abu Ali Muhammad, known as Abu'l-Shalaghlagh, who had fostered Sa'id when he became orphaned as a youth; her name is not recorded.
Sa'id, like Abu'l-Shalaghlagh before him, was the leader of the clandestine Isma'ili missionary network, the ('invitation, calling'), ostensibly propagating the return of a hidden imam, Muhammad ibn Isma'il, as the , the Islamic messiah. Sometime before 899, Sa'id began claiming that he was the actual hidden imam, descended from a line of hidden imams; and that Muhammad ibn Isma'il had been only a fiction and a cover name to mask their activities. These claims may even have begun before Sa'id assumed control of the : the family eunuch Ja'far reports in his memoirs that already Abu'l-Shalaghlagh had secretly claimed to a few senior agents the title of for Sa'id, and the title of for the newly born Abd al-Rahman. These claims caused a schism in the Isma'ili movement in 899, between those who recognized Sa'id's claims to the imamate and those who rejected them and continued to await the return of Muhammad ibn Isma'il as the . The latter are generally known by the term "Qarmatians".
Flight to Sijilmasa
After Sa'id's revelation that he was the hidden imam, some of his most fervent followers launched a series of Bedouin uprisings in Syria against the Abbasid Caliphate. Sa'id had not been consulted beforehand, and the outbreak of these revolts put him in danger, as his identity and location were revealed to the Abbasid government. The Abbasids launched a manhunt against him, so Sa'id took Abd al-Rahman and a few other close members of his household and left Salamiyah for Ramla in Palestine. There the local governor, secretly an Isma'ili convert, hid them from the Abbasid pursuit. The Bedouin rebels, calling themselves 'Fatimids', seized control of much of Syria and established a Shi'a regime on behalf of their hidden master, but despite receiving several letters urging him to join them, Sa'id remained in hiding at Ramla. The rebels were finally defeated in November 903 by the Abbasid army, and their leader captured and interrogated.
This once again forced Sa'id to abandon Ramla for Fustat in Egypt, then ruled by the autonomous Tulunid dynasty. Sa'id, Abd al-Rahman, and their small entourage stayed there until January 905, when the Abbasids invaded the country and overthrew the Tulunid regime. Sa'id decided to move to the Maghreb, in the western fringes of the Muslim world, where one of his agents, the Abu Abdallah al-Shi'i, had converted the Kutama Berbers to the Isma'ili cause, and by 905 had achieved some victories against the autonomous Aghlabid dynasty that ruled Ifriqiya (modern Tunisia and eastern Algeria) under nominal Abbasid suzerainty. On the journey west one of the group's members, Abu Abdallah's brother Abu'l-Abbas Muhammad, was arrested, and the Aghlabids learned about the identity and the appearance of the group's members. As a result, the group skirted the Aghlabid territory along its southern borders and made for the oasis town of Sijilmasa in what is now eastern Morocco. Sa'id, Abd al-Rahman, and their small entourage settled in Sijilmasa, leading the comfortable life of wealthy merchants, for the next four years.