All this had been done by him to prepare for the appearance of Abdullah al-Mahdi Billah, the imam-caliph of the Fatimids. Al-Mahdi was rescued from a prison in Sijilmasa (present-day Morocco) and proclaimed as caliph, ruling from the former residence of the Aghlabids.