Poland’s upper house of parliament on Saturday approved a Supreme Court overhaul, defying the European Union and critics at home who say the legislation would undermine democratic checks and balances.

Tens of thousands of protesters gathered in Warsaw and cities across Poland for candle-lit vigils to protest against the draft bill, as the Senate debated it late into the night.

Some protesters carried Polish and European Union flags, chanting “Free Courts”.

To become law, the proposal still has to be signed by President Andrzej Duda, an ally of the ruling conservative Law and Justice (PiS) party. The eurosceptic PiS argues new rules are needed to make the judiciary accountable and efficient.

But the opposition and judges groups in Poland as well as critics in Brussels say the legislation is a new step by the Polish government towards authoritarianism.

The United States, Poland’s most important ally in NATO, issued a statement urging Poland to ensure any changes respect the constitution.

“We urge all sides to ensure that any judicial reform does not violate Poland’s constitution or international legal obligations and respects the principles of judicial independence and separation of powers,” it said in a statement.

An opinion poll for private television TVN showed on Friday that 55 percent of respondents said Duda should veto the overhaul of the judiciary, while 29 percent wanted him to sign it.

Since coming into power in 2015, the PiS has sought to tighten government influence over courts, and brought prosecutors and state media under direct government control.

It has also introduced restrictions on public gatherings and made it harder for some non-governmental organisations to function.

“We believe that Poland is slowly but systematically turning into a penal institution,” opposition senator Jan Rulewski, a veteran activist of the anti-communism movement, said during the debate, dressed in a prison uniform.

The PiS remains broadly popular among its electorate, despite an upswelling of protest in recent days as it rushed the judiciary overhaul through parliament.

With the economy growing robustly and unemployment at record lows, the party’s nationalist rhetoric infused with Catholic piety resonates strongly among Poland’s conservative voters.

“Foreign meddling”

The government of the EU’s biggest eastern member state has so far dismissed criticism, saying the changes would ensure state institutions serve all Poles, not just the “elites”.

On Wednesday, the EU gave Poland a week to shelve the judicial reforms that Brussels says would put courts under direct government control.

If the PiS government does not back down, Poland could face fines and even a suspension of its voting rights, although other eurosceptic EU governments, notably Hungary, are likely to veto strict punishments.

Senior Czech judges denounced the judicial overhaul in Poland as an attack on the rule of law on Friday.

The PiS has offered some concessions on demand from the president, but has presented criticism from abroad as unacceptable meddling in the domestic affairs of the country, which overthrew communism in 1989 and joined the EU in 2004.

“We will not give into pressure. We will not be intimidated by Polish and foreign defenders of the interests of the elite,” Prime Minister Beata Szydlo said in an address on state television.

While Polish assets have been largely unfazed by the political turmoil earlier this week, the zloty fell over 1 percent against the euro on Friday, underperforming all of the region’s other currencies.