The Banu Ghaniya were a Massufa Sanhaja Berber dynasty and a branch of the Almoravids.[1] Their first leader, Muhammad ibn Ali ibn Yusuf, a son of Ali ibn Yusuf al-Massufi and the Almoravid Princess Ghaniya, was appointed as governor of the Balearic Islands in 1126. Following the collapse of the Almoravid power at the hand of the Almohads in the 1140s, the Banu Ghaniya continued to govern the Balearic Islands as independent emirs until about 1203, with a brief interruption in the 1180s. Later leaders (Ali ibn Ishaq and Yahya) made a determined attempt to reconquer the Maghreb (and in particular Ifriqiya), taking Bougie, Constantine and Algiers, and conquering most of modern Tunisia from about 1180 onwards.
They were influential in the downfall of the Almohad Empire in Eastern Maghrib. In Tunisia, Ali ibn Ishaq adhered to the Abbasid Caliphate and was formally appointed by Al-Mustadi with the title of "heir of the Almoravids".
The Banu Ghaniya clan were relatives of the ruling Almoravid dynasty. Yusuf ibn Tashfin, the Almoravid emir (d. 1161), gave one of his daughters in marriage to Ali ibn Yusuf, the head of Ghaniya clan. He had two sons with her: Yahya and Muhammad. These two became important governors and commanders during the 1120s, under the reign of Ali ibn Yusuf, the son of Yusuf ibn Tashfin who succeeded him as emir . Muhammad was appointed governor of the Balearic Islands in 1126. His brother Yahya was governor of Murcia up to 1133 and then transferred to Valencia in 1134.
For much of the 1130s, Tashfin ibn Ali and Yahya led the Almoravid forces to a number of victories over Christian forces and reconquered some towns, holding back the decline of Almoravid power in Al-Andalus (the Iberian Peninsula). The most significant vicrtory was the Battle of Fraga in 1134, where the Almoravids, led by Yahya, defeated an Aragonese army besieging the small Muslim town of Fraga. Notably, Alfonso I El Batallor was wounded and died shortly after.
The Ghaniya brothers were among the last commanders to hold out as Almoravid power collapsed in al-Andalus. In 1144 or 1145, Yahya was transferred from eastern al-Andalus to Seville in order to counter the rebellion of Ibn Qasi in the west. Starting in 1146, the Almohads arrived in al-Andalus, but Yahya continued to organize resistance against them from Córdoba. Eventually, faced with attacks by the Christian kingdoms to the north and the Almohad invasion, Yahya attempted to reach an agreement with his enemies to remain as lord of Jaén, but he was soon expelled from there too by Alfonso VII of León and Castile. He retreated to Granada, the last outpost of Almoravid rule, where he persuaded the governor to surrender to the Almohads. He died here in late 1148 or early 1149.
Meanwhile, his brother Muhammad remained lord of the Balearics and many remaining members of the Almoravid faction joined him there. He became an independent ruler and founded a new dynasty.
Following the fall of the last Almoravid ruler in Marrakesh in 1147, the Banu Ghainya maintained control of the Balearics and held off several Almohad attacks on the islands. Muhammad remained in power until 1156, when a palace coup replaced him with his son, Ishaq. Under his reign, the kingdom derived revenues through piracy generally aimed at Christian ships. The Almohad caliph, Abu Yaqub Yusuf, sent him an emissary demanding his submission, but Ishaq continued to formally recognize the Abbasid caliphs and attempted to assuage the Almohad caliph with lavish gifts instead. Ishaq died during a pirate expedition in 1183.
Ishaq was initially succeeded by his oldest son, Muhammad. Faced with hostility from both the Christians and Almohads, he sent a message to Marrakesh expressing his agreement to submit to the Almohad caliphs. An Almohad fleet under Ibn Reberter (a Christian mercenary) was sent to take control of the islands. Before it arrived, Muhammad was deposed by the other Almoravid chiefs, who placed his brother 'Ali in power instead. Ali was opposed to Almohad rule and was further pressured to resist them by the Almoravid refugees who lived on the islands. Thus, when the Almohad fleet arrived, he repelled it and captured its commander. Instead of waiting to face an Almohad counter-attack and possible blockade of the islands, Ali decided to take the offensive and attack the Almohads directly in the eastern Maghreb.
See main article: Banu Ghaniya invasion of North Africa.