Turkish rule and piracy
In 1574, Ottoman armies defeated the Spanish, and Tunisia became part of the Ottoman Empire. A period of peace and stability followed, with Turkish imperial rule effected through local governors, known first as deys and later as beys. The first of these, al-Husayn ibn Ali (ruled 1705-1740) founded the Husaynid dynasty and established considerable prosperity in the region.
Much of this prosperity was founded on piracy. This had been an important Tunisian enterprise for several centuries, with Tunisia receiving 'protection money' in the form of bribes from a large number of sea-going nations.
The Barbary Coast of North Africa harboured several corsair bases, all of which flourished during the late 17th and early 18th centuries. The end came in 1815, when the US Navy attacked Tunis and put an end to its piratical source of revenue.