[1][3] It was initially established as an Ottoman province ruled by a pasha (governor) in Tripoli who was appointed from Constantinople, though in practice it was semi-autonomous due to the power of the local Janissaries.
In 1530 the city, along with Malta and Gozo, was ceded by Charles I of Spain to the Knights of St John as compensation for their recent expulsion from the island of Rhodes at the hands of the Ottoman Turks.
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 of North Africa.
The janissaries quickly became the dominant force in Ottoman Libya and were also in charge of collecting taxes; however, Barbary corsairs were the ones who steadily provided income to Tripoli from privateering activities.
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 and enslavement of crews by barbary pirates when the Treaty of Tripoli was signed.
Consequently, the Pasha ordered the execution of all attendees, and chased down the other tribe members, which resulted in the massacre of at least 10,000 people, who eventually sought refuge in neighboring countries, especially Egypt.
The indigenous Senusiyya (or Sanusi) Movement, led by Islamic cleric Muhammad ibn Ali al-Sanusi, 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.
[9] The Ottoman sultan Abdulhamid II twice sent his aide-de-camp Azmzade Sadik El Mueyyed to meet Sheikh Sanusi to cultivate positive relations and counter the West European scramble for Africa.