In March 1440 a Prussian Confederation (German Preussischer Bund, Polish: Związek Pruski) was organisation of cities, gentry and clergy of Prussia formed under the leadership of the Hanseatic League cities Gdansk, Elblag and Torun (then Danzig, Elbing and Thorn, respectively). The cities and gentry of Prussia tried to obtain independence from the Teutonic Knights who, after the conquest of Prussia and Polish Pomerania, had ruled the area for two hundred years. (although their legal status was questioned by the Polish kings).
In February 1454 the Prussian Confederation rose against the Teutonic order's rule, accepting the protection of king Casimir IV of Poland in return for a guarantee of their continued city rights and privileges for gentry. The resulting Thirteen Years' War ended in the Order's defeat and its surrender to the Polish crown (Second Treaty of Thorn, October 1466) of its rights over western Prussia. Eastern Prussia remained under the Knights' rule, but under the nominal overlordship of the Polish king.