him as the 'paramount emir of the Zenata' and sending him frequent gifts, in exchange for the Berber leader's recognizing Umayyad suzerainty. Finally, once he had secured his own position in al-Andalus, in 929 Abd al-Rahman III claimed the title of caliph for himself, establishing the Caliphate of Córdoba, in a direct challenge to al-Mahdi's pretensions, both temporal and religious. Attempts to conquer Morocco In June 917, a Fatimid expedition under Masala ibn Habus sacked the coastal town of Nakur (modern Al Hoceima), the seat of a small emirate. Its ruler was killed, but his sons fled to Malaga on the Spanish coast. Masala also forced the Idrisid ruler of Fes, Yahya IV, to acknowledge Fatimid suzerainty and pay tribute. Idrisid authority was limited to Fes and its environs, while the rest of the country was given to the governorship of Masala's cousin, Musa ibn Abi'l-Afiya. Once Masala withdrew his army, however, the exiled princes of Nakur returned with the backing of Emir Abd al-Rahman III, and in a single night managed to overthrow the Fatimid garrison of the town. In exchange, Nakur's new emir became a vassal of the Emir of Córdoba. Masala returned in 921, forcing the emir of Nakur to abandon his capital without a fight. Influenced by the ambitious Musa ibn Abi'l-Afiya, Masala marched on and attacked Fes. Yahya IV was deposed and sent into exile, and a Fatimid governor was installed in the city. On the return march, Masala once more imposed Fatimid rule over Sijilmasa, installing a pliant Midrarid as a Fatimid vassal. The Idrisids' response to the appearance of the Fatimids varied. Many members of this Alid clan, whose various branches had spread throughout the region of modern northwestern Morocco, accepted al-Mahdi's claims to Alid descent and thus tended to side with the Fatimids, while others resisted Fatimid expansion and tended to turn to the Umayyads of Córdoba for support. One of the latter, al-Hasan al-Hajjam, rose in revolt against Ibn Abi'l-Afiya in 925, and recovered Fes. His rule lasted until 927, when Ibn Abi'l-Afiya retook the city through treachery and had him killed. Ibn Abi'l-Afiya then launched a widespread manhunt against the remaining Idrisids across Morocco, which ended only after local chieftains warned him of the inappropriateness of hunting down descendants of Muhammad. In 929, Ibn Abi'l-Afiya sacked Nakur and extended Fatimid rule over the coast around the mouth of the Moulouya