Polish women protest a legislative proposal for a near-total ban on abortion in Poland. (Geert Vanden Wijngaert/Associated Press)

NATIONALIST POPULISM often looks like a rising, even inexorable force in Europe, particularly in the formerly communist nations on the eastern edge of the European Union. Right-wing governments that base their appeal in part on Islamophobic attacks on immigrants, and liberal values more generally, are entrenched in Poland, Hungary and Slovakia. So it was striking, and heartening, to see a popular backlash in two of those countries this week that dealt the populists stinging rebuffs.

The first came in a referendum last Sunday in Hungary, where Prime Minister Viktor Orban appealed to voters to reject a European Union plan for distributing the refugees that have poured into Europe from the Middle East and Africa. The government spent tens of millions of dollars on a blatantly racist campaign describing all refugees as potential terrorists. Though the E.U. allocated only 1,294 refugees to Hungary, a country of about 10 million, Mr. Orban insisted they could destroy the country’s “Christian” identity.

Opposition parties urged voters to skip the vote, or cast invalid ballots, to prevent the referendum from reaching the 50 percent turnout needed for legal validity. That is what happened: Only 43 percent of voters went to the polls, and 6 percent of those turned in spoiled voting sheets. The referendum, on which Mr. Orban was reported to have spent more than on any advertising campaign in Hungarian history, flopped. Though the prime minister vowed to press on anyway with new anti-migrant laws or a constitutional amendment, the anti-immigrant statement he hoped to send to the E.U. instead became a vote of no confidence in his toxic xenophobia.

Something similar happened in Poland, where legislators of the ruling right-wing Law and Justice Party were pushing a measure that would have turned what is already one of the West’s most restrictive abortion laws into a near-absolute ban. The bill, which won initial approval last month, would have allowed abortions only when the life of the mother was directly threatened; doctors and women who carried out abortions in other circumstances would have faced prison terms of up to five years.

On Monday, tens of thousands of women and men dressed in black turned out in Polish cities to protest the measure. Central Warsaw was paralyzed. Three days later, the ruling party abruptly reversed itself, voting down the measure and withdrawing another that would have severely restricted access to in vitro fertilization. It was the first significant political retreat by Law and Justice, which has refused to give up an attempt to take control of the country’s Constitutional Tribunal and curtail judicial checks on its power despite mass domestic protests and sharp criticism from the European Union.

Mr. Orban and his Polish counterpart, Jaroslaw Kaczynski, are far from vanquished; they still hold strong parliamentary majorities and use state-run television networks to bombard citizens with propaganda. Mr. Orban has endorsed Donald Trump for the U.S. presidency; if the American populist wins, his counterparts in Europe will get a big boost. However, this week’s results showed that, even where the populists are now strongest, their extremist ideas are generating powerful resistance. In Europe as in the United States, liberalism still has its defenders.