As an important trading port between Russia and Scandinavia, Tallinn became a target for expansion by the Teutonic Order and Denmark.

An excerpt from the article 27 facts about Tallinn

In 1219, the city was conquered by the Danish king Waldemar II the Victorious, who ordered the existing castle to be demolished and a new fortress built in its place. And that's probably why in Estonian and Finnish the name Tallinn translates as "Danish city."

In 1227, the Danes lost the city to the Livonian Order, who named the city Rewal.