In 1273 a castle was built on the site of what is now Elbląg by the Teutonic Knights, and in its shadow a prosperous trading town arose that ultimately became part of the Hanseatic League (an association of trading cities). In the 15th century the town was separated from the Order of Teutonic Knights, and became part of the Kingdom of Poland; at the beginning of the 17th century it was for a short time controlled by Sweden (with Axel Oxenstierna, later Chancellor, as provincial governor). From the mid-16th century adherents of evangelical confessions also settled in the town.
When in 1642 Comenius accepted a commission from the Kingdom of Sweden, and he and Chancellor Oxenstierna sought a suitable location for concentrated work on textbooks and other works for Swedish schools, the latter suggested Elbląg as being particularly tolerant of the various Protestant confessions. Comenius lived here until 1648.