Most cities of the region joined or sided with the Prussian Confederation, which in 1454 started an uprising against Teutonic rule and asked the Polish King Casimir IV Jagiellon to incorporate the region to Poland. After the King agreed and signed the act of incorporation, the Thirteen Years' War broke out, ending in a Polish victory. The Second Peace of Thorn (1466) made Royal Prussia a part of Poland. It had a substantial autonomy and a lot of privileges. It formed the Pomeranian Voivodeship, located within the province of Royal Prussia in the Kingdom of Poland, as it remained until being annexed by the Kingdom of Prussia in the partitions of 1772 and 1793. A small area in the west of Pomerelia, the Lauenburg and Bütow Land (the region of Lębork and Bytów) was granted to the rulers of Pomerania as a Polish fief, before being reintegrated with Poland in 1637, and later on, again transformed into a Polish fief, which it remained until the First Partition, when three quarters of Royal Prussia's urban population were German-speaking Protesants.