The president of Poland wielded his veto power on Monday to pull the nation back from further undermining the independence of its judiciary, rejecting two measures that European officials — and tens of thousands of protesters — have condemned as a danger to democracy and the rule of law.

The decision of the president, Andrzej Duda, opened an unexpected new chapter in a debate that has riven Poland, once a model of post-communist democracy in Eastern Europe.

His morning announcement came as a surprise, and a setback, for the ruling right-wing Law and Justice party, which came to power in 2015.