In the 16C, Tunisia became a pawn in the struggles between the Hapsburg Spanish and the Ottoman Turks. After the fall of Granada and the expulsion of the Muslims from Spain in 1492, the Spanish sent ships against North African ports. Meanwhile, two Greek pirates, the brothers El Uruj and Kheireddin (Barbarossa) operated a profitable ‘business’ along the coast. When his brother was killed, Barbarossa turned to the Turks for assistance. In 1534 he conquered Tunis. The following year, Charles V of Spain sent a retaliatory force. Christian slaves turned on Barbarossa, who fled, and opened the gates to Charles. They were rewarded with a vicious massacre and the sacking of the city.
Though Hafsid rule was briefly restored, the Turks recaptured Tunis in 1574. They ruled through deys (military commanders) and their janissaries (Turkish soldiers) It was a time of prosperity for Tunisia in agriculture and trade. Piracy also flourished along the coast, with the beys (governors) sharing in the booty.
In 1705 Hussein ibn Ali Turki was granted the title of pasha, and his dynasty ruled until 1881. Increasingly, the European powers had their eye on Tunisia. They forced an end to piracy, and when the beys ran up debts they were unable to repay, France seized its chance to expand its North African empire.