Musa ibn Abi'l-Afiya
Musa ibn Abi'l-Afiya () was a Miknasa Berber chieftain who ruled the western Maghreb for the Fatimid Caliphate before defecting to the Umayyad Caliphate of Córdoba in 931. He played a central role in the Umayyad–Fatimid rivalry of the time, and is also remembered for his persecution of the Idrisids of Morocco.

Life
Musa ibn Abi'l-Afiya was a chieftain of the Berber tribe of the Miknasa, part of the larger Zenata tribal group, and ruler of the settlements of Tsoul and Taza. Musa is first mentioned during the campaigns of his cousin or uncle, Masala ibn Habus, in the western Maghreb (modern Morocco) on behalf of the newly established Fatimid Caliphate. The primary Arabic sources differ on the chronology and details of the subsequent events, in which Musa played a central role, and modern sources likewise echo these contradictions.

Fatimid viceroy of Morocco
In 917, Masala ibn Habus led a Fatimid invasion into Morocco. He conquered the Emirate of Nekor and defeated the Idrisid ruler of Fes, Yahya IV, forcing him to acknowledge Fatimid suzerainty and pay tribute. Yahya's authority was limited to Fes and its environs, while the rest of the country was given to the governorship of Musa ibn Abi'l-Afiya. The date of this is unclear, with some historians putting it in AH 305 (917/18 CE), others in AH 307 (919/20 CE).

Musa is said by later chroniclers to have become a violent enemy of the Idrisids, and Yahya IV in particular, at that time. More likely, Yahya IV was an obstacle to Musa's own ambitions. As a result, when Masala returned to Morocco two years later (in 919/20 or 921/22, accordingly), influenced by his cousin, he deposed Yahya IV and installed a Fatimid governor in the city. Musa even had Yahya tortured, hoping to make him reveal the location of hidden treasures, before sending him to exile to Asilah.

Musa launched a persecution of the remaining Idrisids, who in response withdrew to scattered fortified strongholds, many of them built at the time for the purpose; the most famous of them is Hajar al-Nasr. This extermination campaign was only tempered by warnings by local Berber chieftains on the inappropriateness of hunting down descendants of Muhammad.

At about the same time—the medieval sources place it in 922 or 928, some modern historians suggest 925—Fes was lost to another Idrisid, al-Hasan al-Hajjam. Al-Hajjam managed to defeat Musa's army in a hard-fought battle at Wadi al-Matahin, but shortly after he was betrayed and taken prisoner by the governor he had appointed over Fes, Hamid ibn Hamdan. Hamid then surrendered the city to Musa.

It is possible that Musa fell out with the Fatimids at about that time; according to the historian Chafik Benchekroun, for the next two years he appears to have governed and campaigned on his own behalf, "without being really neither pro-Fatimid nor pro-Umayyad". This breach was also likely associated with the death of Musa's patron, Masala, in 924.

Umayyad vassal
Fatimid expansion westwards had quickly captured the attention of the other major Islamic power in the region, the Umayyads of al-Andalus (Islamic Spain). The Umayyad ruler Abd al-Rahman III () sent a fleet to seize Melilla in 927, establishing it as a military base in the Moroccan coast, followed by Ceuta in 931. Abd al-Rahman also entered into an alliance with the Zenata chieftain Ibn Khazar against the Fatimids, in exchange for the Berber leader's recognizing Umayyad suzerainty. Finally, in 929 Abd al-Rahman III claimed the title of caliph for himself, establishing the Caliphate of Córdoba, in a direct challenge to Fatimid pretensions, both temporal and religious.

In response, in 929/30 Musa assaulted the emir of Nekor, al-Mu'ayyad, an Umayyad client, and sacked the city. The city and its fortifications were almost razed to the ground, and traces of the destruction visited by Musa on Nekor were still visible at the time of Ibn Hawqal's visit a few decades later. In the same year, Musa also attacked the Sulaymanid dynasty, rulers in what is now northwestern Algeria. He defeated the Sulaymanid ruler, al-Hasan ibn Isa ibn Abi'l-Aysh, but the latter found refuge with a cousin who ruled an offshore island. Lacking a fleet, Musa could not pursue him. 

Soon after, in the year 931, Musa officially declared his allegiance to the Umayyad caliph, Abd al-Rahman III. The reason for this is unclear, and debated by modern scholars, but was likely related to the capture of Ceuta by the Umayyads, which exposed Musa to possible Umayyad military action. It is also in the same year that Masala's brother and successor as governor of Tahert, Yasal, died, leading to a bloody succession dispute in which Fatimid troops fought against the supporters of Masala's son, who for a time also recognized Umayyad suzerainty. Yasal's son Hamid likewise was imprisoned at about the same time; after escaping in 939, he too would defect to the Umayyads.

As an Umayyad vassal, Musa received valuable support from al-Andalus: an Umayyad ship attacked the Sulaymanids on their island, and the port town of Melilla became a refuge for members of Musa's family. On the other hand, in 933 Musa lost control of Fes to Hamid ibn Hamdan and an unknown Idrisid leader. Very shortly after, Hamid was betrayed and killed by another local leader, Ahmad ibn Abi Bakr of the Abu Sahl clan, who sent Hamid's head to Musa. Ahmad ibn Abi Bakr in turn also remained in control of Fes for a short time, as the Fatimid counteroffensive launched in retaliation of Musa's defection under the general Maysur al-Fata, captured the city. The Fatimids were successful in forcing Musa to abandon his strongholds of Tsoul and Warzigha and flee to the south, but in the long term, their expeditions failed to reverse the situation: more and more, the local rulers turned to Córdoba.

The subsequent career and fate of Musa is unclear, as the sources are contradictory. The account of the 11th-century Andalusi historian Ibn Hayyan, considered the most reliable by J. D. Latham, holds that he died in August 938, and was succeeded by his son Madyan; two other sons are mentioned in the same source, Abu Munqidh and Muhammad. The 14th-century Rawd al-Qirtas on the other hand insists that Musa, pursued by Maysur and the Idrisids, spent many years wandering, virtually alone, through the desert and his domains, and died either in 939/40 or in 952/53, and was succeeded by his son Ibrahim. The 14th-century Moroccan historian Ibn 'Idhari further reports that in 948, Musa sent two of his sons as envoys to the court of Córdoba, while according to the 11th-century Andalusi historian al-Bakri, in 949 Musa finally defeated and captured the pro-Fatimid Sulaymanid ruler, al-Hasan ibn Isa ibn Abi'l-Aysh.

References

Sources
 
 
 
 

10th-century deaths
10th-century people from the Fatimid Caliphate
Generals of the Fatimid Caliphate
Miknasa
People from the Caliphate of Córdoba
10th-century Berber people
10th-century monarchs in Africa
Berber monarchs
10th century in Morocco