Fürstbistum Ermland
The city joined the Prussian Confederation in 1440 and rebelled against the Teutonic Knights in 1454 upon the outbreak of the Thirteen Years' War to join Poland under King Casimir IV Jagiellon. The townspeople took the castle and recognized the Polish king as the rightful ruler. Although the Teutonic Knights recaptured the city the following year, it was retaken by Polish troops in 1463. The Second Peace of Thorn in 1466 confirmed Olsztyn as part of the Kingdom of Poland. Administratively it was located in the Prince-Bishopric of Warmia within the provinces of Royal Prussia and Greater Poland.