The first record of a settlement next to the castle of the Pałuk family was noted in 1365. It became a town in 1434. In 1773 it was incorporated into Prussia during the second of the Partitions of Poland. Local people took part in the various insurrections which unsuccessfully tried to regain freedom in the 19th century. After World War I the town became part of the Second Polish Republic. In September 1939 it was quickly occupied by German troops and was incorporated into the Nazi Reich as part of Warthegau. The boys' school in the town was surrounded by barbed wire fences and additional concrete huts were added, so that it could become a prisoner of war camp for captured officers, French, Polish and Soviet as Oflag XXI-B. In 1943 the camp was changed to a camp for U.S. Army officers as Oflag 64.
The town returned to Poland after being freed by Soviet troops on 21 January 1945.