In 1227 the German warrior monks known as the Livonian Brothers of the Sword (German crusaders) conquered the Danish castle and started building a new one out of stone on the southwestern corner of Toompea Hill. They also built the first stone cathedral on the center of the hill in the place of a wooden one built by the Danes in 1219. Soon a first wave of 200 German merchants settled in the new German outpost. The Order was decimated in the Battle of Saule in 1236 against the Lithuanians with the surviving Livonian Brothers being incorporated into the Order of Teutonic Knights who in 1238 returned Northern Estonia (and Tallinn) to the Danes. The new cathedral that had been left unfinished was completed and consecrated by the Danes n 1240. The hill-town of Tallinn would be the capital of Danish Estonia for more than 130 years (1346).

By the end of the 13th century Tallinn had evolved into a dual body of an upper (Toompea / Castle) and a lower town. The castle was more densely populated while the lower town had acquired its administrative autonomy and an autonomous council. The two were deemed as one entity, the capital of the Danish Duchy of Estonia that had city rights equal to other German merchant cities like Lübeck, a city network which would later evolve into the powerful Hanseatic League.