Poland's President Andrzej Duda has vetoed two out of three contentious bills that are widely seen as assaults on the independence of the judicial system and are part of a planned legal overhaul by the ruling party that has sparked days of nationwide protests.

Duda said he vetoed the judiciary reforms to make sure they were constitutional and vowed on Monday to present new proposals in the near future.

On Saturday, the upper house gave final approval to a bill that would remove all current Supreme Court judges immediately except those approved by the justice minister, who is also the prosecutor general.

Parliament had earlier passed a bill giving it the right to name most of the members of the National Council of the Judiciary, which would nominate future candidates for the president to appoint to the Supreme Court.

In announcing his decision against the two bills on Monday, Duda broke openly for the first time with Jaroslaw Kaczynski, leader of the ruling Law and Justice Party (PiS).

Duda is closely aligned with the party and has supported its agenda since taking office in 2015.

Duda said the reforms, including a clear-out of Supreme Court judges, were in line with popular expectations and that many Poles had grievances against the justice system.

"However, as the president, I could not accept them and I use the right of veto because they require changes that ensure their conformity with the constitution," he said.

Duda was hand-picked by Kaczynski as the party's presidential candidate in 2015 and has loyally supported the party's conservative nationalist agenda, not vetoing any of its laws until now.

His step won the praise of members of the political opposition who had been urging him to veto the bills.

Al Jazeera's Sonia Gallego, reporting from Warsaw, said the decision is seen as an enormous victory in the country.

"The announcement comes as a surprise because many people were anticipating that the president might not take this decision as he was a former member of the PiS and seen by many to be sympathetic to the party as well," she said.

READ MORE: Poland is turning authoritarian

"Critics are saying the president himself was feeling uneasy with the direction the party was going in and that he had issues particularly about the Supreme Court being under the jurisdictions of the ministry of justice.

"It was something that was not only criticised by the people of Poland but also the EU and the US state department as it has been seen as a power grab by the Law and Justice Party in order to get their influence as far and wide as possible in the country."

Thousands of protesters had taken to the streets across Poland in recent days to oppose the bill, including huge crowds who held a candle-lit protest outside the Supreme Court on Sunday night urging Duda to veto the changes.

The European Commission had threatened to halt Poland's voting rights over the proposed reforms - a so-called "nuclear option" that the EU had never invoked - while the US had also expressed concern.

The PiS, which began making changes to the judiciary after coming to power in late 2015, has argued resistance to the initiatives is a case of the elite defending their privileges.