The town has throughout history interchangeably been part of both Poland and Germany. It is located at a formerly important crossroad, where the Monastic State of the Teutonic Knights built a fortification in the Middle Ages. The town was probably established in the 1370s and grew up around the military outpost. In 1382 the town received German Kulm law city rights. No traces remain of the castle, but remnants of the medieval city wall have been incorporated in some later houses. Up until the 20th century, the town economy consisted mostly of fishing, agriculture, crafts and local trade. It was the centre of a cloth manufacturing industry from the 16th century until the 19th century, when it had to close due to competition from more modern industries. A railway connection to the town was established in 1878. In 1939, the town had 2,292 inhabitants. The town had a Jewish community and a small synagogue prior to World War II and the Holocaust.