of Danzig, Elbing, Kneiphof, Thorn and other Prussian cities founded the Prussian Confederation to free themselves from the overlordship of the Teutonic Knights. Due to the heavy losses and costs after the war against Poland and Lithuania, the Teutonic Order collected taxes at steep rates. Furthermore, the cities were not allowed due representation by the Teutonic Order. In February 1454, the Prussian Confederation asked King Casimir IV of Poland to support their revolt and to incorporate the region to the Kingdom of Poland. King Casimir IV agreed and signed the act of incorporation in Kraków on 6 March 1454. The Thirteen Years' War, the longest of the Polish–Teutonic wars, (also known as the War of the Cities) broke out. Various cities of the region pledged allegiance to the Polish King in 1454. The Second Peace of Thorn in October 1466 ended the war and provided for the Teutonic Order's cession of its rights over the western half of its territories to the Polish Kingdom, which became the Polish province of Royal Prussia and the remaining part of the Order's land became a fief and protectorate of Poland, considered part of one and indivisible Kingdom of Poland. In accordance to the peace treaty, from now on, every Grand Master was obliged to swear an oath of allegiance to the reigning Polish king within six months of taking office, and any new territorial acquisitions by the Teutonic Order, also outside Prussia, would also be incorporated into Poland. The Grand Master of the Teutonic Order became a prince and counselor of the Polish king and the Kingdom of Poland. Formation of a new nobility While the Knights of the Teutonic Order formed a thin ruling class by themselves, they have extensively used mercenaries, mostly German, from the Holy Roman Empire, to whom they granted lands in return. This gradually created a new class of landed nobility. Due to several factors, among which was the high rate of early death in battle, these lands became concentrated over time in the hands of a relatively small number of noblemen each having a vast estate. This nobility would evolve to what is known as the Prussian Junker nobility. 16th century and aftermath Transformation to Ducal Prussia During the Protestant Reformation, endemic religious upheavals and wars occurred across the region. In 1525, during the aftermath of the Polish-Teutonic War (1519–1521), Sigismund I the Old, King of Poland,