The pope installed the Teutonic Knights, a crusading order that reported directly to the Papacy, as rulers of the area. Under their governance, woodlands were cleared and marshlands made arable. Many cities and villages were founded upon those lands, including Marienburg (now the Polish Malbork), the seat of the Knights' grand master. Many of these cities joined the Hanseatic League of northern European trading cities.
In 1410, with the death of the emperor Rupert, war broke out between the Teutonic Knights and a Polish-Lithuanian alliance supported by Ruthenian and tiny Tatar auxiliary forces, in which Poland and Lithuania were the winners following their victory at Battle of Grunwald. The Order assigned Henry XIII, duke of Reuss-Plauen, to defend Pomerania. He moved rapidly to bolster the defence of Marienburg, was elected vice-grand master and saved the Marienburg headquarters. He then became grand master and in 1411 concluded the First Treaty of Thorn with king Ladislaus II of Poland.
In March 1440, the Hanseatic cities of Gdansk, Elblag and Torun (then Danzig, Elbing and Thorn, respectively) and gentry (mainly from Culmerland founded the Prussian Confederation with other Prussian cities to free themselves from the overlordship of the Teutonic Knights. They asked king Casimir IV of Poland to supported their revolt and incorporate Prussia into Poland (February 1454), and when he agreed the War of the Cities or Thirteen Years' War started. The resulting Second Treaty of Torun (October 1466 provided for the Teutonic Order's cession to the Polish crown of its rights over the western half of its territories, which became the province of Polish or Royal Prussia. The eastern half of Prussia remained under the rule of the Order and its successors, until 1660 under Polish overlordship.
During the Reformation endemic religious upheavals and wars occurred, and in 1525, the last Grand Master of the Teutonic Knights, Albert of Brandenburg, a member of a cadet branch of the house of Hohenzollern, resigned his position, adopted the Lutheran faith and assumed the title of "Duke of Prussia." In a deal partially brokered by Martin Luther Ducal Prussia became the first Protestant state. In 1618 the dukedom of Prussia passed to the senior Hohenzollern branch, the ruling Margraves of Brandenburg.