After Danes and Germans conquered the area in 1227, Estonia was ruled initially by Denmark in the north, by the Livonian Order, an autonomous part of the Monastic state of the Teutonic Knights and by Baltic German ecclesiastical states of the Holy Roman Empire. From 1418 to 1562 the whole of Estonia formed part of the Livonian Confederation. After the Livonian War of 1558–1583, Estonia became part of the Swedish Empire until 1710/1721, when Sweden ceded it to Russia as a result of the Great Northern War of 1700–1721. Throughout this period the Baltic-German nobility enjoyed autonomy, and German served as the language of administration and education.