By the end of the 10th century Sfax had become an independent city-state. The city was conquered by Roger II of Sicily in 1148 and occupied until it was liberated in 1156 by local forces, and was briefly occupied by European forces again, this time by the Spanish, in the 16th century. Sfax became an integral base of the Barbary piracy, prompting an unsuccessful invasion by Venice in 1785. In the late 19th century Sfax and the rest of Tunisia were conquered by France and incorporated into the French empire. During World War II, the Axis powers used the city as a major base until they were defeated by British forces. After World War II, Tunisia was returned to France, but gained its independence in 1956