The ancient history of Tallinn dates back to the first century, when a fortress was built in Iru, which also included a settlement. For reasons that are not known at this time, this fortress was abandoned in middle of the 11th century and the Lindanise Castle was built on the current Toompea Hill, which can be considered the centre of the ancient Revala county.
The first reliable written records on Tallinn can be found in the Livonian Chronicle of Henry. According to the Chronicle, in June 1219, the Danish fleet, which was led by King Valdemar II, landed at the Lindanise Castle. The Battle of Lindanise took place between the Danish troops and Estonians on the grounds of what has become Tallinn, on 15 June 1219. The Danes won the difficult battle. According to legend, the battle took a turn to favour the Danes right after a white flag with a red cross, the current Dannebrog flag of Denmark, had fallen from the sky. At the end of the 13th century Tallinn joined the Hanseatic League.
Driven by internal political turmoil and lack of money, the King of Denmark sold his possessions in Northern Estonia, including Tallinn, to the Teutonic Order in 1346. Tallinn became a Hanseatic city. The development of trade in Tallinn was based on the privileges received already in the 13th century. Tallinn acquired the right of coinage in 1265 and the warehouse right was granted to the city in 1346. The city of Tallinn and Harju-Viru vassals surrendered to the Swedish power in 1561 and Tallinn became the centre of a new administrative unit – the Governorate of Estonia.
During 1700–1721, the Baltic Sea region was pillaged by the Great Northern War. The main opponents were the Swedish Empire and the Tsardom of Russia, who fought to dominate the area. On 29 September 1710, Tallinn capitulated to Russian troops without a fight. At the turn of the 19th–20th century, Estonianness became a new source of vitality in Tallinn. In 1991, Tallinn became the capital of Estonia that had just regained its independence.