Abu Abdallah Muhammad IV al-Mutawakkil

Abu Abdallah Muhammad IV al-Mutawakkil (أبو عبد الله محمد المتوكل) was the Hafsid caliph of Ifriqiya from 1494 to 1526.

He came to power following an extended fight over the succession following the death of the caliph Abu 'Amr 'Uthman in 1488. Like many of his predecessors he endowed places of learning. The Abdaliyya library which he founded in the Al-Zaytuna Mosque around 1500 has survived intact into modern times. Leo Africanus recorded his love of music, singing and the company of female singers performing the Ma'luf music of the court. The main political and military events of his reign concerned the rise in corsairing and the Spanish invasion of the Hafsid domains.

Barbarossa brothers and raids on Christian shipping
In 1492 the fall of Granada in Spain was followed by the Rebellion of the Alpujarras (1499–1501) and the expulsion of many Muslims from the domains of Castile and Aragon. Many of those who had been expelled established themselves in the cities of North Africa and took to corsairing, attacking Christian shipping. Around 1500 Oruç Reis and his brother Hayreddin Barbarossa from Lesbos established themselves in the port of La Goulette near Tunis with two raiding galiots. Abu Abdallah Muhammad allowed them to operate from his port in return for a share of their booty.

Their first success was the seizing a trading galley and its escort belonging to Pope Julius II off Elba in 1504, which he towed back into Tunis in triumph. This attracted other captains to their side and their forces grew. Next year, 1505, they captured of a large Spanish ship heading towards Naples carrying five hundred soldiers, and a great quantity of gold coins to recruit and pay the army in the Kingdom of Naples. In 1510 they moved to their base from Tunis to Djerba, perhaps because feared punitive attacks by the Spanish. Nevertheless, a 1513 Genoese raid by Andrea Doria destroyed a number of Barbarossa ships in La Goulette.

Spanish invasions
The raids of the Barbary corsairs were one reason that prompted Spain to pursue the Reconquista across the Straits of Gibraltar into North Africa. In 1510 they struck at both the western and eastern extremities of the Hafsid domains, and Pedro Navarro took first Bejaia (in modern Algeria) and Tripoli (in modern Libya). Pedro Navarro then attempted to seize Djerba, but the Barbarossa brothers helped defend the island and drive them off.

Nevertheless, the position of Abu Abdullah Muhammad continued to deteriorate. He enlisted the assistance of the Barbarossas to try to regain Bejaia in 1514 and again in 1515. The Spanish drove them off but they succeeded in taking the coastal town of Jijel. As their hold on the North African coast grew stronger the Spanish turned for assistance to Emperor Charles V and the Barbarossas, in their turn, to Selim the Grim. In Algiers, the Barbarossas established a government rather than merely a base, and in 1519 they recognised Ottoman suzerainty. After this Algiers became a base for Ottoman expansion and the former Hafsid domains of Bejaia and Annaba were lost to them in 1522, while in 1520 Djerba fell to the Spanish under Hugo of Moncada.