The coastal region of what is today Libya was ruled by the Ottoman Empire from 1551 to 1911, as the Eyalet of Tripolitania (Ottoman Turkish: ایالت طرابلس غرب Eyālet-i Trâblus Gârb) or Bey and Subjects of Tripoli of Barbary from 1551 to 1864 and as the Vilayet of Tripolitania (Ottoman Turkish: ولايت طرابلس غرب Vilâyet-i Trâblus Gârb) from 1864 to 1911. It was also known as the Kingdom of Tripoli, even though it was not technically a kingdom, but an Ottoman province ruled by pashas (governors). The Karamanli dynasty ruled the province as de facto hereditary monarchs from 1711 to 1835, despite remaining under nominal Ottoman rule.
Besides the core territory of Tripolitania, Barca was also considered part of the kingdom of Tripoli, because it was de facto ruled by the Pasha of Tripoli, also the nominal Ottoman governor-general.
A remnant of the centuries of Turkish rule is the presence of a population of Turkish origin, the Kouloughlis.
By the beginning of the 16th century the Libyan coast had minimal central authority and its harbours were havens for unchecked bands of pirates. Spain occupied Tripoli in 1510, but the Spaniards were more concerned with controlling the port than with the inconveniences of administering a colony. In 1530 the city, along with Malta and Gozo, were ceded by Charles I of Spain to the Knights of St John as compensation for their recent expulsion from Rhodes at the hands of the Turks. Christian rule lasted then until 1551, when Tripoli was besieged and conquered by famed Ottoman admirals Sinan Pasha and Turgut Reis. Declared Bey and later Pasha of Tripoli, Turgut Reis submitted the tribes of the interior and several cities like Misrata, Zuwara, Gharyan, and Gafsa in the next decade. These efforts contributed to cement the foundations of a statal structure in what is today Libya, but control from Constantinople remained loose at best, much like in the rest of the Barbary Coast.
Under the Ottomans, the Maghreb was divided into three provinces, Algiers, Tunis, and Tripoli. After 1565, administrative authority in Tripoli was vested in a pasha directly appointed by the Sultan in Constantinople. The sultan provided the pasha with a corps of janissaries, which was in turn divided into a number of companies under the command of a junior officer or bey. The janissaries quickly became the dominant force in Ottoman Libya. As a self-governing military guild answerable only to their own laws and protected by a divan (a council of senior officers who advised the pasha), the janissaries soon reduced the pasha to a largely ceremonial role.
In 1711, Ahmed Karamanli, an Ottoman cavalry officer and son of a Turkish officer and Libyan woman, seized power and founded the Karamanli dynasty, which would last 124 years. The 1793–95 Tripolitanian civil war occurred in those years.
In May 1801 Pasha Yusuf Karamanli demanded from the United States an increase in the tribute ($83,000) which it had paid since 1796 for the protection of their commerce from piracy when the Treaty of Tripoli was signed. The demand was refused, an American naval force blockaded Tripoli, and the desultory First Barbary War dragged on until 3 June 1805.
The Second Barbary War (1815, also known as the Algerian War) was the second of two wars fought between the United States and the Ottoman Empire's North African regencies of Algiers, Tripoli, and Tunis, known collectively as the Barbary States.
Reassertion of Ottoman authority
In 1835 the government of Sultan Mahmud II took advantage of local disturbances to reassert their direct authority and held it until the final collapse of the Ottoman Empire. As decentralized Ottoman power had resulted in the virtual independence of Egypt as well as Tripoli, the coast and desert lying between them relapsed to anarchy, even after direct Ottoman control was resumed in Tripoli. The indigenous Senussi Movement, led by Islamic cleric Sayyid Mohammed Ali as-Senussi, called on the countryside to resist Ottoman rule. The Grand Senussi established his headquarters in the oasis town of Jaghbub while his ikhwan (brothers) set up zawiyas (religious colleges or monasteries) across North Africa and brought some stability to regions not known for their submission to central authority. In line with the expressed instruction of the Grand Sanusi, these gains were made largely without any coercion.
It was one of the first Ottoman provinces to become a vilayet after an administrative reform in 1865, and by 1867 it had been reformed into the Tripolitania Vilayet.
The highpoint of the Sanusi influence came in the 1880s under the Grand Senussi's son, Muhammad al-Mahdi as-Senussi, who was a skilled administrator and a charismatic orator. With 146 lodges spanning the entire Sahara, he moved the Senussi capital to Kufra. Harsh Ottoman rule only fuelled the appeal of the Senussi Movement's call to repel foreign occupation. Remarkably, Mohammed al-Mahdi succeeded where so many had failed before him, securing the enduring loyalty of the Amazigh tribes of Cyrenaica. Over a 75‑year period the Ottoman Turks provided 33 governors and Libya remained part of the empire—although at times virtually autonomous—until Italy invaded in 1911, as the Ottoman Empire was collapsing.
The Italo-Turkish War was fought between the Ottoman Empire and the Kingdom of Italy from September 29, 1911 to October 18, 1912.
As a result of this conflict, the Ottoman Turks ceded the provinces of Tripolitania, Fezzan, and Cyrenaica to Italy. These provinces together formed what became known as Libya.