Thanlyin first came to prominence in the 15th century as the main port city of the Hanthawaddy Kingdom, replacing a silted up Bago port. In 1539, the city became part of the Kingdom of Taungoo. In 1599, the city fell to the Rakhine forces led by the Portuguese mercenary Filipe de Brito e Nicote, who was made governor of the city. De Brito declared independence from his nominal Rakhine masters in 1603, defeated the invading Rakhine navy in 1604 and 1605, and successfully established Portuguese rule under the Portuguese viceroy of Goa. In 1613, Burmese king Anaukpetlun recaptured the city, and executed Brito by impalement, a punishment reserved for defilers of Buddhist temples.
Thanlyin remained the major port of the Taungoo kingdom until the mid-18th century. In the 1740s, Thanlyin was made the base of the French East India Company for their help in the Mon's reestablishment of Hanthawaddy Kingdom. The arrangement lasted until 1756 when King Alaungpaya of Konbaung dynasty captured the city. From then on, the importance has shifted to Yangon across the river, which Alaungpaya founded just a year earlier.
Thanlyin became part of the British Empire in 1852 after the Second Anglo-Burmese War. The British made the city into the oil refinery center of the country in the early 20th century to process the oil shipped from central Burma. The refinery was destroyed during World War II. The Thanlyin refinery was rebuilt in 1957, and underwent expansion in 1979 with Japanese assistance. In 1979 a pipeline was completed between Syriam and the Mann oilfield.
Since the 1990s, the city has undergone major changes. Thanlyin was finally connected to Yangon by road in 1993 when the Thanlyin Bridge was built. In the late 1990s, Thilawa Port was built to handle the container ships away from Yangon's ports. The city is home to a national university in Myanmar Maritime University, and local universities in the University of East Yangon and Technological University, Thanlyin. The city's population has increased from 43,000 in 1983 to 123,000 in 1996.