It was originally built by the Teutonic Knights, a German Roman Catholic religious order of crusaders, in a form of an Ordensburg fortress. The Order named it Marienburg (Mary's Castle). The town which grew around it was also named Marienburg. In 1466, during the division of Prussia into eastern and western parts the castle and town became part of western Royal Prussia. It served as one of the several Polish royal residences, interrupted by several years of Swedish occupation, and fulfilling this function until the Kingdom of Prussia re-united Prussia and claimed the castle at the time of the First Partition of Poland in 1772. During conquest by the Soviet Union the land was granted to Poland in 1945. Heavily damaged after World War II, the castle was renovated under the auspices of modern-day Poland in the second half of the 20th century and most recently in 2016. Nowadays, the castle hosts exhibitions and serves as a museum.