Timor drew Portuguese ships for its sandalwood, and the first recorded voyage from Malacca came in 1516. Dili itself is much younger. In 1769 the governor, António José Teles de Meneses, shifted the government and 1,200 people eastward. He meant to stop at Vemasse but settled at Dili, on land belonging to the Motael kingdom, whose leader was on good terms with the Portuguese.
The site was wetland, good for rice. One part of the first settlement was for people of mixed descent and newcomers from other Portuguese possessions, which became Bidau. In 1834 the governor José Maria Marques rebuilt the town on a grid and had the marshes between the shore and Lahane drained. The town stayed modest for a long time: one visitor found the governor's house a low whitewashed cottage and everything else mud and thatch.
Dili was declared a city in 1863 and was still tiny in the 20th century: about 6,000 people in 1950, and fewer than 30,000 before 1975. Motael Church was begun in 1901, and a new cathedral opened in 1937. Then the Second World War reached the island. Australian and Dutch troops arrived in 1941 despite Portuguese objections, the Japanese invaded, and later Allied bombing finished much of what the invasion began. The city's archives were wiped out in 1779, 1890, 1975 and 1999.
After the 1974 revolution in Portugal, Timorese parties formed and a civil war followed. The UDT staged a coup on 11 August 1975, and the last Portuguese governor fled to Atauro Island. Fretilin declared independence in Dili on 28 November. Indonesian paratroopers landed on 7 December, and in July 1976 Indonesia annexed the territory as its 27th province.
Indonesian rule left buildings behind: the Immaculate Conception Cathedral, the Integration Monument and Cristo Rei all date from then, and the population climbed past 100,000 by 1999. It also left a resistance. Residents kept safe houses and passed messages to the outside world, and Motael Church sheltered activists in 1991. Indonesian forces stormed it, and Sebastião Gomes was shot. On 12 November, soldiers fired on a funeral procession at Santa Cruz cemetery. The shooting was filmed, and the world reacted with condemnation of Indonesia's hold on Timor.
The 1997 Asian financial crisis brought down Suharto, and his successor agreed to a referendum. East Timor voted for independence in August 1999. Violence followed: international media counted 145 deaths in the first 48 hours, much of the city burned, and 120,000 people became refugees. An Australian-led force landed on 20 September.
In 2002 Dili took on the role of capital of a sovereign Timor-Leste. Under UN administration the city grew by more than 10% a year. Trouble came back in April 2006, when a split in the army spilled into street fighting between easterners and westerners, and about half the city's residents were displaced. Most had returned by 2009, when Jose Ramos-Horta launched a City of Peace campaign with a marathon, a cycling tour and tree planting. The 2022 census counted 324,269 people in the municipality.