Polish President Andrzej Duda. (Fabrizio Bensch/Reuters)

FOR SEVERAL years, a group of countries in Central Europe that successfully made the transition from Soviet Communist satellites to democratic members of the European Union has been engaged in what looks like a forced march backward toward authoritarianism. Power-hungry governments in Hungary, Poland and Romania have dismantled judicial checks and balances, silenced independent media, and cynically stirred nationalist passions against outsiders, ranging from E.U. organs to the financier George Soros. It was consequently heartening this week when Poland’s ruling party, under pressure both from Brussels and its own citizens, felt obliged to retreat.

President Andrzej Duda, who just three months ago was mocking the E.U. as “an imaginary community,” on Monday signed a hastily enacted law reinstating senior judges who had been forced out of their jobs, in effect complying with an order from the E.U.’s highest court. The purge of a third of the 72 judges on the Supreme Court was one of a series of steps the right-wing Law and Justice party had taken to gain control over the judiciary, including packing the Constitutional Court and the body that nominates new judges.

Poland’s democracy remains in danger: The politicization of the security services, transformation of state-owned media into propaganda organs, and pressure on independent journalists and civil society continue. But in bowing to the E.U. court, Law and Justice and its leader, Jaroslaw Kaczynski, have showed that the European Commission does have the leverage to fight the authoritarian drift, at least in Poland. It can do so not because of its military or economic might, but because a majority of Poles want their country to remain a part of democratic Europe.

That was one message from recent local elections, the first to be held in Poland since Law and Justice gained a majority in parliament with about 40 percent of the popular vote three years ago. Turnout reached record levels, reflecting the polarization the party has brought about in a society that once united against communism. While Law and Justice swept rural areas, it was trounced in the cities, losing 103 out of 107 mayoral votes. With elections for the European Parliament coming up in May, and an even more crucial vote for the Polish Parliament due within a year, the government has suddenly begun to stress its allegiance to Europe.

Reversing Poland’s political backslide will ultimately require opposition electoral victories, but in the meantime, the E.U. can do more to contain the damage. It should continue pressing for a reversal of all the actions taken by Law and Justice to compromise the judiciary. The Trump administration, for its part, ought to reconsider the political bet it has made on the Polish nationalists, whom it has openly favored. It’s an ugly cause whose demise may have already begun.