In 1793 it was annexed by Prussia in the Second Partition of Poland, in 1807 regained by Poles and included within the short-lived Duchy of Warsaw, in 1815 re-annexed by Prussia, and from 1871 to 1918 was also part of Germany. The population took part in Polish uprisings of 1830–1831 and 1848. The town was subjected to Anti-Polish policies including Germanisation, however it remained a center of Polish resistance, and Poles established various organizations. In November 1918, after World War I, Poland regained independence, and in December 1918, local Poles liberated the town from the Germans, and it was re-integrated with Poland. Local Poles took part in multiple battles of the Greater Poland uprising (1918–19), in which 18 of them were killed. In the 1920s Polish nun Ursula Ledóchowska, today considered a saint of the Catholic Church, founded the Congregation of the Ursulines of the Agonizing Heart of Jesus in Pniewy.