The city was founded in the 7th century BC, by the Phoenicians, who gave it the Libyco-Berber name Oea (or Wy't), suggesting that the city may have been built upon an existing older native Berber town. 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 later 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. It was part of the Ottoman Empire between the 16th and 19th centuries.