1230 when the son of Abu Hafs declared himself independent. During the reign of the Hafsid dynasty from their capital Tunis, fruitful commercial relationships were established with several Christian Mediterranean states. In the late 16th century the coast became a pirate stronghold. Ottoman Tunisia In the last years of the Hafsid dynasty, Spain seized many of the coastal cities, but these were recovered by the Ottoman Empire. The first Ottoman conquest of Tunis took place in 1534 under the command of Barbarossa Hayreddin Pasha, the younger brother of Oruç Reis, who was the Kapudan Pasha of the Ottoman Fleet during the reign of Suleiman the Magnificent. However, it was not until the final Ottoman reconquest of Tunis from Spain in 1574 under Kapudan Pasha Uluç Ali Reis that the Ottomans permanently acquired the former Hafsid Tunisia, retaining it until the French conquest of Tunisia in 1881. Initially under Turkish rule from Algiers, soon the Ottoman Porte appointed directly for Tunis a governor called the Pasha supported by janissary forces. Before long, however, Tunisia became in effect an autonomous province, under the local bey. Under its Turkish governors, the beys, Tunisia attained virtual independence. The Hussein dynasty of beys, established in 1705, lasted until 1957. This evolution of status was from time to time challenged without success by Algiers. During this era the governing councils controlling Tunisia remained largely composed of a foreign elite who continued to conduct state business in the Turkish language. Attacks on European shipping were made by corsairs, primarily from Algiers, but also from Tunis and Tripoli, yet after a long period of declining raids the growing power of the European states finally forced its termination. Under the Ottoman Empire, the boundaries of Tunisia contracted; it lost territory to the west (Constantine) and to the east (Tripoli). The plague epidemics ravaged Tunisia in 1784–1785, 1796–1797 and 1818–1820. In the 19th century, the rulers of Tunisia became aware of the ongoing efforts at political and social reform in the Ottoman capital. The Bey of Tunis then, by his own lights but informed by the Turkish example, attempted to effect a modernizing reform of institutions and the economy. Tunisian international debt grew unmanageable. This was the reason or pretext for French forces to establish a protectorate in 1881. French Tunisia (1881–1956) In 1869, Tunisia declared itself bankrupt and an international financial commission took control over its economy. In 1881,