The Spaniards seized Tripoli in June 1510. The human cost of resisting the new invaders was enormous. Around 5,000 local people were killed and thousands more were taken captive. A letter from the Spanish fleet commander stated: "Bodies were scattered throughout the city, there was no place to set your foot on."
Tripoli was later ceded to the Knights of St. John in 1530, with an aim to use it as a base to further attack the Muslims in the north coast of Africa, but the knights had run into the determined resistance of the local people.
The people of Tripoli took refuge in the castle of Tajoura, some 20 kilometers to the east, and began to fight the crusaders.
In 1551, Libyans wisely sought help from the Ottoman Empire, which was the Islamic Caliphate at the time. This step was to change the tides of the war.
The Ottoman administration sent Murad Ağa, a military official, to Tajoura -an eastern suburb of Tripoli- with a mighty fleet and thousands of soldiers.
He settled in Tajoura and waged relentless combat against the crusaders.
Though he laid siege to Tripoli, he could not capture the city, the massive defensive fortifications of the castle made it difficult to conquer. Murad Ağa requested reinforcements from the Ottoman administration to liberate the region.
Sultan Kanuni, the ruler of the Ottoman Empire at the time, sent Turgut Reis, one of the greatest figures in Turkish naval history. In August 1551, the crusaders surrendered and the massive citadel fell after Turgut Reis imposed a blockade on the fortress.
Before the Ottoman rule, Libya lacked a unitary system of government. As the Ottomans expanded into the rest of Libya's provinces Barqa, and Fezzan, there was a concept of a modern state developing.
The Ottomans era persisted for more than 3 centuries, in which Libya underwent a series of stages, mostly marked by success.
Education and development came about, as the new rulers encouraged learning and worked in developing cities and agriculture, as well as settling Bedouins. They also revived the caravan trade across the desert, which stimulated growth and prosperity.
The Ottoman architecture is still evident in mosques, schools, traditional markets, such as the famous Souq al-Mushir in Tripoli, in addition to other official and private buildings.
In 1878 the Ottomans Empire was challenged by the growing western Europe powers, meanwhile, Italy set its eyes on Libya, but Sultan Abd al-Hamid II stayed vigilant of the Italian greed.
He sent weapons, military assists and 15,000 soldiers to assist the troops on Libyan territory; his moves caused Italy to postpone its invasion of Libya.
Later, Libya was occupied by Italy in 1911 during the period of the European-backed "Committee of Union and Progress" which came to power in a coup against the Ottoman Empire on 27 April 1909, after isolating Sultan Abdul Hamid II.