WARSAW — Despite making major gains in provincial assemblies, Poland’s populist ruling party suffered a sweeping defeat in municipal voting in a set of elections that concluded on Sunday, confirming that Poland is a nation ever more deeply divided between its liberal cities and its conservative countryside.

In elections for local and regional offices around the country, the governing Law and Justice won just four of 107 mayoral races, down from the 11 it won four years ago.

Yet the party secured the most seats in nine out of 16 provincial assemblies and won outright majorities in six of them — a significant gain from the one provincial government it controlled after the elections in 2014.

The recent elections, which were the first nationwide vote since Law and Justice swept to power in a parliamentary vote in 2015, had the highest turnout in local contests since the fall of communism in 1989. The turnout in the first round of balloting was 17 to 20 percentage points higher than that four years ago, and the turnout in the runoff round, which is usually lower, was in many places almost identical to that from the first round, said Lukasz Pawlowski, the head of the Institute of Local Government Studies.