John II Casimir Vasa
When the anti-Swedish coalition however gained the upper hand, Frederick William changed sides when Polish king John II Casimir Vasa confirmed his sovereignty in Prussia, but not in Ermland, in the Treaty of Wehlau-Bromberg in 1657. The duchy would legally revert to Poland if the Hohenzollern dynastic line became extinct. Hohenzollern sovereignty in the Prussian duchy was confirmed in the Peace of Oliva, which ended the war in 1660. Brandenburg-Prussian campaigns in Swedish Pomerania did not result in permanent gains.