Polish President Andrzej Duda has announced he is vetoing a controversial law to replace Supreme Court judges with government nominees.
Three key judicial reforms have been passed by Poland's parliament, prompting days of demonstrations across the country.
Before they become law, they require approval by the president.
The changes have also set Poland's right-wing government on a collision course with the European Union.
The European Commission had threatened to impose sanctions this week if the reforms were not scrapped. European Council President Donald Tusk, a former Polish prime minister, had warned of a "black scenario that could ultimately lead to the marginalisation of Poland in Europe".
Why did president step in?
"As president I don't feel this law would strengthen a sense of justice," Mr Duda said in a statement broadcast on national television. "These laws must be amended."
He said he was vetoing two of the new laws but approving a third, which gives the justice minister the right to name the heads of Poland's lower courts.
The Law and Justice (PiS) government has strongly rejected claims that the reforms are a move towards authoritarian rule and has expressed disappointment at Mr Duda's decision to wield a veto.
Mr Duda had already intervened last week in an attempt to find a compromise and his latest step came as a surprise.
He is himself a former member of the populist ruling party and he had already rejected a meeting on the crisis with Donald Tusk.
He said he had discussed the reforms at the weekend with legal experts as well as judges. The most influential voice, he said, was that of Zofia Romaszewska, a veteran dissident from the communist era who told Mr Duda she did not want to go back to the days when "the general prosecutor could do virtually anything".
She was jailed during the years of martial law in the early 1980s but is now one of the president's advisers. Ms Romaszewska told Polish media it was completely out of the question for the attorney general to take charge of the Supreme Court.
Opposition MPs also praised the role of protesters in influencing the decision.
Demonstrations have taken place in dozens of Polish cities, from Poznan and Lublin to Krakow, Gdansk and Warsaw, and there have been calls for the protests to continue.
Mr Duda warned that no change should lead to a separation of the state from society.
What's wrong with the reforms?
Poland's judicial system is widely seen as slow and reforms are seen as necessary. "I'm absolutely a supporter of this reform, but a wise reform," said President Duda.
The three reforms give the justice minister and MPs broad powers and have prompted alarm from the US, as well as the EU.
- The first reform requires all Supreme Court judges to step down and gives the justice minister the power to decide who should stay on
- The second gives politicians control over who sits on the National Judiciary Council which nominates Supreme Court judges
- The third gives the justice minister the right to select and dismiss judges in lower courts
The president's initial compromise plan last week watered down the government's bid to push through its nominees for the National Judiciary Council, by requiring the support of another political party.
In his statement, the president said he regretted that a draft law on reforming the Supreme Court had not been handed to him before a vote in the lower house of parliament, the Sejm.
The president also took issue with the strengthened role of the justice minister, who also acts as attorney general in Poland.
What happens next?
In theory, the Polish parliament could now challenge the president's veto.
Law and Justice has a simple majority in the Sejm but needs a three-fifths majority if it decides to reject Mr Duda's decision. It could theoretically achieve that with the support of a smaller party, Kukiz'15, but that is not seen as certain.
A more likely step would be to spend the next weeks redrafting the two bills that the president has turned down and seek his approval. The protest movement has celebrated its success so far but is now pushing for the president to veto the third reform as well.
Much now depends on the man seen as the real power behind the government, Jaroslaw Kaczynski.