The port city of Tunis was an important outpost for the Ottoman Empire and the Barbary Pirates under the rule of Barbarossa. Sometime around 1510, Barbarossa and his brother convinced the ruler of Tunis to allow the pirates to make the city a base of operations. Soon, Barbarossa became in charge of a large fleet of Turkish sailors and increased his possessions by taking many north African port towns. In an attempt to protect these possessions from the Spanish, Barbarossa submitted control of these port cities to the Ottoman Empire. Barbarossa, however, used a power struggle among those close to the throne to overthrow Hassan, the ruler of Tunis. Hassan appealed to Spanish King Charles V for help. Charles, whose fleet was previously defeated by Barbarossa in 1538, responded by sending a fleet of over 20,000 soldiers and invaded the city of Carthage and subsequently captured the cities of Tunis and Goletta while liberating 20,000 Christian slaves. Hassan was temporarily returned to power, but was again overthrown in 1542.
In 1574, however, Tunis was invaded and conquered by Turks from the Ottoman Empire after being liberated from Ottoman Control by Austria in 1573. During this time, piracy near Tunis increased in frequency. Tunisians ships frequently patrolled parts of the north Mediterranean plundering and destroying any foreign ship that happened into its waters. Prisoners were captured by the thousands and sold in Tunis as slaves. Pirates operating out of Tunis remained active for many decades and Tunis amassed magnificent riches and slave labor as a result. Tunis continued to amass wealth well into the 1700's as European powers decided to sign treaties that ensured the safe passages of its ships through the Mediterranean Sea.
In the 1800's, however, piracy in Tunis declined with the sacking of Algiers by the British general Lord Exmouth. In 1830, after French forces had captured Algiers, the city of Tunis was forced to put an end to their Christian slave trade and was also forced to concede one of its island possessions. The Ottoman Empire, which had turned a blind eye to the activities occurring in Tunis, soon made Tunis a Turkish possession and sought to maintain positive relationships with France.
British Ship engaging with Barbary ship near Tunis