Denmark rose as a great military and mercantile power in the 12th century. It had an interest to end the occasional Estonian and Couronian pirate attacks that threatened its Baltic trade. Danish fleets made attacks against Estonia in 1170, 1194, and 1197. In 1206, King Valdemar II and archbishop Andreas Sunonis made a raid to Ösel island (Saaremaa). The islanders were forced to submit and the Danes built a fortress there, but they found no volunteers to man it. They burned it down themselves and left the island. However, they laid a claim to Estonia as their possession, which was recognised by the pope.
In 1219, Valdemar gathered a fleet of hundreds of ships against the Estonians, led by the archbishop, bishops and the army of Rugians under their prince Wizlav. They landed in Lyndanisse (Tallinn) harbor in the province of Revelia (Revala, Rävälä, later merged into Harria province) in northern Estonia. According to a legend, the first ever flag of Denmark fell from sky and helped the Danes to win the battle against Revelians and Harrians. The date of the battle, June 15, is still celebrated as Valdemarsdag (the national "flag day") in present Denmark.
The Order and Denmark agreed to divide Estonia but had quarrel over the exact borders. In 1220 King of Denmark agreed to submit southern Estonian provinces Sakala and Ugaunia that were already conquered by Sword Brethren. Bishop Albert submitted to Denmark the provinces of Harria (Harju), Vironia (Viru) and Jerwia (Järva). 1227 the Livonian Order conquered all Danish territories, but, according to the treaty of Stensby, returned Harria and Vironia to Denmark in 1238 while Jerwia was ceded to the Order. Due to its status as a Danish territory, Estonia is included in a nationwide Danish taxation list Liber Census Daniæ (Valdemar Sejrs Jordebog) (1220–41), an important geographic and historic document. The list contains about 500 Estonian place names and names of 114 local vassals.
The capital of Danish Estonia was Lyndanisse (Tallinn) from their invasion in 1219. Danes built a fortress there which is called Castrum Danorum in the chronicle of Henry of Livonia or "Danish castle". Estonians still call their capital "Tallinn", which according to one popular theory is a derivation from Taani linna, having exactly the same meaning. Danes built a big stone castle in the Domberg (Toompea) area. Lyndanisse became also the seat of a bishopric with was a suffragan to the archbishop of Lund. Around the castle, German settlers founded a major trading town. Lyndanisse (Reval, in German) was granted Lübeck city rights (1248) and joined the Hanseatic League. Even today, the Danish influence can be seen in such symbols as the city of Tallinn's coat of arms is a shield with the Danish cross; and Estonia's coat of arms uses three lions very similar to the Danish coat of arms, but in the Estonian colors of yellow and blue.
In Vironia, the main power centers were Wesenberg (Rakvere) and Narva, built on site on old Estonian fortresses known in Old East Slavic chronicles as Rakovor and Rugodiv, respectively. Wesenberg was granted Lübeck city rights on 1302 by King Erik Menved. Narva received these rights in 1345.
The rule of Denmark was not very strong in the province. Danish army was sent to the province only occasionally. In 1240–42, Denmark went to war against Novgorod and tried to extend its rule to the land of Votians. King Valdemar sent his sons Abel and Canute to support the campaign of his vassals but did not gain any new territories. The Danish king Erik Plogpennig visited Estonia in 1249 and the Danish fleet sailed to Lyndanisse in 1268 and 1270 against Russian and Lithuanian threats.
The local military power was based on powerful vassals of Danish king, who received big land grants in exchange of military service. Most of the vassals were Germans from Westphalia area but some (Clemens Esto, Otto Kivele, Odwardus Sorseferæ etc.) were local Estonian elders. The chronicler Ditleb Alnpeke (1290) complains that king of Denmark accepts Estonians as his vassals. In 1248, the vassals and burgers of Lyndanisse already had a local legislative body ritterschaft.
While the province was split between pro-Danish party (bishop Olaf of Lyndanisse) and pro-German party (captain Marquard Breide), the Estonians of Harria started a big rebellion in 1343 (St.George's Night Uprising). The province was occupied by the Livonian Order as a result. In 1346, the Danish dominions in Estonia (Harria and Vironia) were sold for 10 000 marks to the Livonian Order, ignoring the promise by Christian II in 1329 never to abandon or sell its Estonian territories. The king of Denmark even made public statement about "repenting" for breaking that promise and asked forgiveness from the Pope.