In 1454, upon the request of the anti-Teutonic Prussian Confederation, the town was incorporated into the Kingdom of Poland by King Casimir IV Jagiellon, and the castle was handed over to Poland. The town sided with Poland in the subsequent Thirteen Years' War, after which in the 1466 peace treaty the Teutonic Knights renounced any claims to the town. It was officially named Dzierzgoń in the documents, and administratively it was located in the Malbork Voivodeship in the Polish province of Royal Prussia in the Greater Poland Province of the Polish Crown. The castle became the seat of local starosts (local administrators). From 1508 the city was renamed to Kiszpork. Guilds developed under Polish rule, and trade flourished in the town. Local starosts granted privileges to the guilds of shoemakers, bakers, tailors, butchers, and wheelwrights. In 1622, the Polish Sejm merged the functions of the Kiszpork/Dzierzgoń starost and the Malbork voivode. Sejmiks (local parliaments) of the local nobility were held in the castle. A battle between Poland and Sweden was fought in Kiszpork in 1627, during the Polish–Swedish War (1626–1629). In 1647 a privilege was granted, allowing the trade in wine.