He was given the oath of allegiance in Málaga as caliph, assumed the honorific al-Mutaʾayyad bi-Allah, and appointed his nephew Ḥasan ibn al-Muʿtalī governor of Ceuta (1).
Not long afterward, Muḥammad al-Barbarī (2) asked Idrīs for help against the army of Seville. Idrīs supplied him with a force commanded by Ibn Baqanna; they routed the Sevillian troops, which were led by Ismāʿīl, son of the qāḍī Ibn ʿAbbād. Ismāʿīl was killed and his head was brought to Idrīs ibn ʿAlī, but it reached him while he was ill; he survived only two days and died. He left two sons: Muḥammad, who would be known as al-Mahdī, and Ḥasan, who received the title al-Sāmī (3).
Al-Muʿtalī bi-Allah had earlier imprisoned Muḥammad and Ḥasan, the sons of his cousin al-Qāsim ibn Ḥammūd, in Algeciras, placing them under the watch of a Maghribī guard. When news of al-Muʿtalī’s death reached this guard, he gathered the Berbers and Black troops in the city, released Muḥammad and Ḥasan, and proclaimed: “These two are your lords; hasten to obey them.”
Muḥammad was accordingly acclaimed and took control of Algeciras, though he did not assume the title of caliph. His brother Ḥasan stayed with him for a time, then chose the path of renunciation: he donned wool, turned away from worldly affairs, and performed the pilgrimage with his sister Fāṭimah (4).
When Naja the Slav, who was in Ceuta, heard of Idrīs’s death, he crossed to Málaga accompanied by Ḥasan ibn Yaḥyā ibn ʿAlī. Ibn Baqanna’s strength collapsed and he fled (5), taking refuge in the fortress of Mārash, a day’s ride from Málaga. Ḥasan ibn Yaḥyā was then given the oath of allegiance as caliph.