The Protestant Reformation was introduced in the town soon after 1519. The territory came back to Polish King Władysław IV Vasa as a reverted fief and was integrated with the Polish Pomeranian Voivodeship after the 1637 death of Bogislaw XIV, Duke of Pomerania. As Lębork was the leading city of the territory, it became the seat of the eldership ("starostwo"). The starosts were Stanisław Koniecpolski and Jakub Wejher. The Counter-Reformation was largely ineffective in the Lutheran town. Lębork was occupied by Swedes in the Northern Wars. To gain an ally against Sweden during the Deluge, King John II Casimir of Poland gave the Lauenburg and Bütow Land to Margrave Frederick William of Brandenburg-Prussia as a hereditary fiefdom in the 1657 Treaty of Bromberg. The Swedish troops burnt Lauenburg before their retreat in 1658, destroying seventy houses and the town hall. Frederick William released the town from tax duties for five years to aid in its rebuilding. Lauenburg suffered a second fire in 1682. King John III Sobieski made peaceful attempts to reintegrate the town directly to Poland, but to no avail.