When an envoy of Ferdinand III, Holy Roman Emperor proposed Polish acceptance of Hohenzollern sovereignty in Prussia in turn for Frederick William I joining the anti-Swedish camp and supporting the Habsburg candidate in the next imperial elections, the "Great Elector" signaled his willingness to change sides. Thereupon, Polish king John III Sobieski concluded the secret Treaty of Wehlau on 19 September 1657, wherein the Hohenzollern sovereignty over the Duchy of Prussia, but not Ermland, was confirmed in turn for an "eternal alliance" between Brandenburg-Prussia and Poland and religious freedom for the Catholics in Prussia.