Voters check lists at a polling station during the first round of the local elections on October 21, 2018 in Warsaw | Janek Skarzynski/AFP via Getty Images Poland’s ruling party wins local polls, but opposition claims victory The vote heralds a fierce contest for European and parliamentary elections in 2019.

WARSAW — Polish voters sent a warning to Poland's rulers in the first electoral test in three years.

Local elections on Sunday saw the right-wing Law and Justice (PiS) party win nationally, according to exit polls, but the result was disappointing enough to put wind in the sails of the opposition. It also underscored how divided the country is.

The outcome was closely watched ahead of the European Parliament election this May and the vote for Polish parliament next fall and the country's presidency in 2020.

According to exit polls, which will have to be confirmed by actual vote counts expected on Tuesday or Wednesday, PiS took 32.3 percent. That’s worse than the 37.6 percent it got in the 2015 parliamentary election, but better than the 26.9 percent it took in local elections in 2014.

The leading opposition party, Civic Platform, won 24.7 percent, almost the same as it won in 2015. Its former coalition partner, the agrarian Polish People’s Party, took 16.6 percent.

“We’ve created an effective anti-PiS" — Grzegorz Schetyna, Civic Platform leader

The biggest blow to PiS came in Warsaw. Rafał Trzaskowski, the Civic Platform candidate, romped home with 54.1 percent, easily defeating Deputy Justice Minister Patryk Jaki, who had run an energetic campaign but was unable to break through in a city that is Poland’s liberal heartland.

PiS also failed to win any of the country’s other large cities.

PiS foes upbeat

Opposition activists are putting a positive spin on the result, saying that nationally, the two leading anti-PiS parties took home 41 percent, almost 10 percentage points more than Law and Justice.

The ruling party put on a brave face. Jarosław Kaczyński, the leader of PiS and the country’s de facto ruler, called the result a victory, pointing out that it is his party’s best outcome in local elections. But the message to the party faithful was more sobering.

Generous social welfare policies have earned the gratitude of poorer voters.

“We have to work, work and again work,” Kaczyński said. “It’s the beginning of an election campaign which will end in May 2020. There’s a lot of heavy work ahead of us, but we’ll manage.”

Although Civic Platform came second, the result is a triumph for its leader Grzegorz Schetyna. A behind-the-scenes political operator with little personal charisma, Schetyna was able to rebuild a party shattered by the 2015 election and form a coalition with the liberal Modern party and a smaller left-wing grouping led by Barbara Nowacka, a leading feminist.

“We’ve created an effective anti-PiS,” Schetyna told his supporters.

Divided country

The result shows divisions in Poland over the PiS program, which has prompted concern in Brussels and other EU capitals that the country is backsliding on its democratic commitments, fraying ties with European allies like Germany and France.

That tension with Brussels was underlined on Friday, when the European Court of Justice ordered Poland to backtrack on reforms to the Supreme Court until the ECJ can hear a case on whether those changes violate EU standards.

Law and Justice has the support of a significant minority of Poles, especially those in smaller towns and social conservatives, who fervently back its anti-immigrant message leavened with bolstering national pride. Generous social welfare policies have earned the gratitude of poorer voters.

The urban liberals who formed Poland’s traditional ruling and business class in the quarter century of post-communist transformation have mobilized against PiS. The party’s efforts to toughen up abortion laws saw tens of thousands of angry women take to the streets. The country’s largest cities have seen frequent protests against PiS’s efforts to bring the court system under tighter political control, and over worries that PiS will eventually lead Poland out of the EU — an aim the party denies.

The resulting polarization has created two big camps, making smaller parties largely irrelevant.

“This is an indefinite result,” said Marek Migalski, a political scientist at the University of Silesia. “Both sides are calling it a victory.”

The exit polls only measure the vote on a national scale, but the real race is for the 16 regional assemblies — a level of government that has the crucial job of spending most of the billions in EU funds that have transformed the country over the last decade.

“These elections are very important because they really start an election marathon which will last until 2020” — Grzegorz Schetyna

There, PiS has traditionally done badly because it has trouble building local coalitions. In 2014, the party won in six regions, but was only able to govern in one. Sunday’s elections are likely to produce similar problems for Law and Justice. Exit polls indicate the party has a lead in nine regions, mainly in the more traditional, religious and poorer east of the country; Civic Platform officials predicted that PiS will only end up governing in a couple of regions.

The main takeaway for PiS is that the party didn’t get any bonus from the voters for its three years in power that have coincided with a continuing economic boom, but it’s not facing a disaster either in upcoming elections.

“We still have to improve some things, but we have a chance to reach all Poles and persuade them about us,” Prime Minister Mateusz Morawiecki said after polls closed.

For the opposition, Sunday’s result is the first sign that PiS is vulnerable, something that will give its supporters a boost.

“These elections are very important because they really start an election marathon which will last until 2020,” Schetyna said.