The city was founded in the 7th century BC, by the Phoenicians, who gave it the Libyco-Berber name Oea (or Wy't).  The Phoenicians were probably attracted to the site by its natural harbour, flanked on the western shore by the small, easily defensible peninsula, on which they established their colony. The city then passed into the hands of the rulers of Cyrenaica (a Greek colony on the North African shore, east of Tripoli, halfway to Egypt), although the Carthaginians later wrested it from the Greeks.
By the latter half of the 2nd century BC it belonged to the Romans, who included it in their province of Africa, and gave it the name of "Regio Syrtica". Around the beginning of the 3rd century AD, it became known as the Regio Tripolitana, meaning "region of the three cities", namely Oea (i.e., modern Tripoli), Sabratha and Leptis Magna. It was probably raised to the rank of a separate province by Septimius Severus, who was a native of Leptis Magna.
In spite of centuries of Roman habitation, the only visible Roman remains, apart from scattered columns and capitals (usually integrated in later buildings), is the Arch of Marcus Aurelius from the 2nd century AD. The fact that Tripoli has been continuously inhabited, unlike e.g., Sabratha and Leptis Magna, has meant that the inhabitants have either quarried material from older buildings (destroying them in the process), or built on top of them, burying them beneath the streets, where they remain largely unexcavated.
There is evidence to suggest that the Tripolitania region was in some economic decline during the 5th and 6th centuries, in part due to the political unrest spreading across the Mediterranean world in the wake of the collapse of the Western Roman empire, as well as pressure from the invading Vandals.
According to al-Baladhuri, Tripoli was, unlike Western North Africa, taken by the Muslims very early after Alexandria, in the 22nd year of the Hijra, that is between 30 November 642 and 18 November 643 AD. Following the conquest, Tripoli was ruled by dynasties based in Cairo, Egypt (first the Fatimids, and later the Mamluks), and Kairouan in Ifriqiya (the Arab Fihrids, Muhallabids and Aghlabid dynasties). For some time it was a part of the Berber Almohad empire and of the Hafsids kingdom.
16th to 19th centuries
In 1510, it was taken by Pedro Navarro, Count of Oliveto for Spain, and, in 1530, it was assigned, together with Malta, to the Knights of St. John, who had lately been expelled by the Ottoman Turks from their stronghold on the island of Rhodes.
Finding themselves in very hostile territory, the Knights enhanced the city's walls and other defenses. Though built on top of a number of older buildings (possibly including a Roman public bath), much of the earliest defensive structures of the Tripoli castle (or "Assaraya al-Hamra", i.e., the "Red Castle") are attributed to the Knights of St John.
Having previously combated piracy from their base on Rhodes, the reason that the Knights were given charge of the city was to prevent it from relapsing into the nest of Barbary pirates it had been prior to the Spanish occupation. The disruption the pirates caused to the Christian shipping lanes in the Mediterranean had been one of the main incentives for the Spanish conquest of the city.
The knights kept the city with some trouble until 1551, when they were compelled to surrender to the Ottomans, led by Muslim Turk Turgut Reis. Turgut Reis served as pasha of Tripoli, during his rule he adorned and built up the city, making it one of the most impressive cities along the North African Coast. Turgut was also buried in Tripoli after his death in 1565. His body was taken from Malta, where he had fallen during the Ottoman siege of the island, to a tomb in the mosque he had established close to his palace in Tripoli. The palace has since disappeared (supposedly it was situated between the so-called "Ottoman prison" and the arch of Marcus Aurelius), but the mosque, along with his tomb, still stands, close to the Bab Al-Bahr gate.
After the capture by the Ottoman Turks, Tripoli once again became a base of operation for Barbary pirates. One of several Western attempts to dislodge them again was a Royal Navy attack under John Narborough in 1675, of which a vivid eye-witness account has survived.
Effective Ottoman rule during this period (1551–1711) was often hampered by the local Janissary corps. Intended to function as enforcers of local administration, the captain of the Janissaries and his cronies were often the de facto rulers.
In 1711, Ahmed Karamanli, a Janissary officer of Turkish origin, killed the Ottoman governor, the "Pasha", and established himself as ruler of the Tripolitania region. By 1714, he had asserted a sort of semi-independence from the Ottoman Sultan, heralding in the Karamanli dynasty. The Pashas of Tripoli were expected to pay a regular tributary tax to the Sultan, but were in all other aspects rulers of an independent kingdom. This order of things continued under the rule of his descendants, accompanied by the brazen piracy and blackmailing until 1835, when the Ottoman Empire took advantage of an internal struggle and re-established its authority.
The Ottoman province (vilayet) of Tripoli (including the dependent sanjak of Cyrenaica) lay along the southern shore of the Mediterranean between Tunisia in the west and Egypt in the east. Besides the city itself, the area included Cyrenaica (the Barca plateau), the chain of oases in the Aujila depression, Fezzan and the oases of Ghadames and Ghat, separated by sandy and stony wastelands.
In the early part of the 19th century, the regency at Tripoli, owing to its piratical practices, was twice involved in war with the United States. In May 1801, the pasha demanded an increase in the tribute ($83,000) which the U.S. government had been paying since 1796 for the protection of their commerce from piracy under the 1796 Treaty with Tripoli. The demand was refused by third President Thomas Jefferson, and a naval force was sent from the United States to blockade Tripoli.
The First Barbary War (1801-1805) dragged on for four years. In 1803, Tripolitan fighters captured the U.S. Navy heavy frigate Philadelphia and took its commander, Captain William Bainbridge, and the entire crew as prisoners. This was after the Philadelphia was run aground when the captain tried to navigate too close to the port of Tripoli. After several hours aground and Tripolitan gun boats firing upon the Philadelphia, though none ever struck the Philadelphia, Captain Bainbridge made the decision to surrender. The Philadelphia was later turned against the Americans and anchored in Tripoli Harbor as a gun battery while her officers and crew were held prisoners in Tripoli. The following year, U.S. Navy Lieutenant Stephen Decatur led a successful daring nighttime raid to retake and burn the warship rather than see it remain in enemy hands. Decatur's men set fire to the Philadelphia and escaped.
A notable incident in the war was the expedition undertaken by diplomatic Consul William Eaton with the objective of replacing the pasha with an elder brother living in exile, who had promised to accede to all the wishes of the United States. Eaton, at the head of a mixed force of US Soldiers, Sailors, and Marines, along with Greek, Arab and Turkish mercenaries numbering approximately 500, marched across the Egyptian / Libyan desert from Alexandria, Egypt and with the aid of three American warships, succeeded in capturing Derna. Soon afterward, on 3 June 1805, peace was concluded. The pasha ended his demands and received $60,000 as ransom for the Philadelphia prisoners under the 1805 Treaty with Tripoli.
In 1815, in consequence of further outrages and due to the humiliation of the earlier defeat, Captains Bainbridge and Stephen Decatur, at the head of an American squadron, again visited Tripoli and forced the pasha to comply with the demands of the United States. See Second Barbary War.
Late Ottoman era
In 1835, the Ottomans took advantage of a local civil war to reassert their direct authority. After that date, Tripoli was under the direct control of the Sublime Porte. Rebellions in 1842 and 1844 were unsuccessful. After the French occupation of Tunisia (1881), the Ottomans increased their garrison in Tripoli considerably.
Italy had long claimed that Tripoli fell within its zone of influence and that Italy had the right to preserve order within the state. Under the pretext of protecting its own citizens living in Tripoli from the Ottoman government, it declared war against the Ottomans on 29 September 1911, and announced its intention of annexing Tripoli. On 1 October 1911, a naval battle was fought at Prevesa, Greece, and three Ottoman vessels were destroyed.
By the Treaty of Lausanne, Italian sovereignty was acknowledged by the Ottomans, although the caliph was permitted to exercise religious authority. Italy officially granted autonomy after the war, but gradually occupied the region. Originally administered as part of a single colony, Tripoli and its surrounding province were a separate colony from 26 June 1927 to 3 December 1934, when all Italian possessions in North Africa were merged into one colony. By 1938, Tripoli had 108,240 inhabitants, including 39,096 Italians.
Tripoli underwent a huge architectural and urbanistic improvement under Italian rule: the first thing the Italians did was to create in the early 1920s a sewage system (that until then lacked) and a modern hospital.
In the coast of the province was built in 1937–1938 a section of the Litoranea Balbia, a road that went from Tripoli and Tunisia's frontier to the border of Egypt. The car tag for the Italian province of Tripoli was "TL".
Furthermore, the Italians – in order to promote Tripoli's economy – founded in 1927 the Tripoli International Fair, which is considered to be the oldest trade fair in Africa. The so-called Fiera internazionale di Tripoli was one of the main international "Fairs" in the colonial world in the 1930s, and was internationally promoted together with the Tripoli Grand Prix as a showcase of Italian Libya.
The Italians created the Tripoli Grand Prix, an international motor racing event first held in 1925 on a racing circuit outside Tripoli (it lasted until 1940). The first airport in Libya, the Mellaha Air Base was built by the Italian Air Force in 1923 near the Tripoli racing circuit (actually is called Mitiga International Airport).
Tripoli even had a railway station with some small railway connections to nearby cities, when in August 1941 the Italians started to build a new 1,040-kilometre (646-mile) railway (with a 1,435 mm (56.5 in) gauge, like the one used in Egypt and Tunisia) between Tripoli and Benghazi. But the war (with the defeat of the Italian Army) stopped the construction the next year.
Tripoli was controlled by Italy until 1943 when the provinces of Tripolitania and The city fell to troops of the British Eighth Army on 23 January 1943. Tripoli was then governed by the British until independence in 1951. Under the terms of the 1947 peace treaty with the Allies, Italy relinquished all claims to Libya.
This section needs expansion
. You can help by adding to it. (February 2016)
Colonel Muammar Gaddafi became leader of Libya on 1 September 1969.
On 15 April 1986, U.S. President Ronald Reagan ordered major bombing raids, dubbed Operation El Dorado Canyon, against Tripoli and Benghazi, killing 45 Libyan military and government personnel as well as 15 civilians. This strike followed US interception of telex messages from Libya's East Berlin embassy suggesting the involvement of Libyan leader Muammar Gaddafi in a bomb explosion on 5 April in West Berlin's La Belle discothèque, a nightclub frequented by US servicemen. Among the alleged fatalities of the 15 April retaliatory attack by the United States was Gaddafi's adopted daughter, Hannah.
The United Nations sanctions against Libya imposed in April 1992 under Security Council Resolution 748 were lifted in September 2003, which increased traffic through the Port of Tripoli and had a positive impact on the city's economy.
Libyan civil war
Front lines during the Battle of Tripoli (20–28 August 2011)
In February and March 2011, Tripoli witnessed intense anti-government protests and violent government responses resulting in hundreds killed and wounded. The city's Green Square was the scene of some of the protests. The anti-Gaddafi protests were eventually crushed, and Tripoli was the site of pro-Gaddafi rallies.
The city defenses loyal to Gaddafi included the military headquarters at Bab al-Aziziyah (where Gaddafi's main residence was located) and the Mitiga International Airport. At the latter, on 13 March, Ali Atiyya, a colonel of the Libyan Air Force, defected and joined the revolution.
In late February, rebel forces took control of Zawiya, a city approximately 50 km (31 mi) to the west of Tripoli, thus increasing the threat to pro-Gaddafi forces in the capital. During the subsequent battle of Zawiya, loyalist forces besieged the city and eventually recaptured it by 10 March.
As the 2011 military intervention in Libya commenced on 19 March to enforce a U.N. no-fly zone over the country, the city once again came under air attack. It was the second time that Tripoli was bombed since the 1986 U.S. airstrikes, and the second time since the 1986 airstrike that bombed Bab al-Azizia, Gaddafi's heavily fortified compound.
In July and August, Libyan online revolutionary communities posted tweets and updates on attacks by rebel fighters on pro-government vehicles and checkpoints. In one such attack, Saif al-Islam Gaddafi and Abdullah Senussi were targets. The government, however, denied revolutionary activity inside the capital.
Several months after the initial uprising, rebel forces in the Nafusa Mountains advanced towards the coast, retaking Zawiya and reaching Tripoli on 21 August. On 21 August, the symbolic Green Square, immediately renamed Martyrs' Square by the rebels, was taken under rebel control and pro-Gaddafi posters were torn down and burned.
During a radio address on 1 September, Gaddafi declared that the capital of the Great Socialist People's Libyan Arab Jamahiriya had been moved from Tripoli to Sirte, after rebels had taken control of Tripoli.
In August and September 2014 Islamist armed groups extended their control of central Tripoli. The Council of Deputies parliament set up operations on a Greek car ferry in Tobruk. A rival New General National Congress parliament continued to operate in Tripoli.