WARSAW — Poland's ruling Law and Justice party (PiS) government is turning up the heat on the country's judges, and it could jeopardize the recent thaw in relations with Brussels.

It’s even prompted the country's Supreme Court to warn the result could be Poland exiting the EU.

Last week, three PiS MPs filed a bill that would penalize judges who question the legitimacy of legal changes made by the government, saying it is forbidden to "show hostility toward other authorities of the Republic of Poland and its constitutional organs, as well as to criticize the basic principles of the Republic of Poland."

It’s a direct response to a November ruling from the Court of Justice of the EU, which said Polish courts will have to determine whether a newly created disciplinary chamber for judges and the National Council of the Judiciary, which is responsible for judicial appointments, are “sufficiently independent.”

Last year the government changed the composition of the council, and most members are now appointed by the PiS-controlled parliament.

The court's current head, Małgorzata Gersdorf, has been openly critical of the ruling party's legal changes.

Those changes are part of a far-reaching overhaul of the legal system by PiS, which argues that the reforms are needed to rid the courts of communist-era judges.

Skeptics point out that fewer than a tenth of Polish judges predate the end of communism in 1989, and charge that the changes are aimed at putting the legal system under the control of the ruling party.

Debate on the legislation begins on Thursday. On Wednesday evening, thousands of people took to the streets in dozens of Polish towns and cities to protest.

High stakes

Although PiS won an overall majority in the lower house of parliament in October for the second time, it lost control of the Senate and the race for president next year is expected to be very close.

Losing the presidency would jeopardize efforts by party leader Jarosław Kaczyński to completely transform the country — a reason for the final push to take control of the court system now.

As a result of the CJEU ruling, some Polish courts have been directing questions to the country's Supreme Court, asking whether new judges appointed by the National Council of the Judiciary should be allowed to rule on cases. That's raised the possibility of legal confusion, with various courts questioning whether some judges and the cases they have ruled on are valid or not.

The bill now before parliament would forbid courts from questioning the validity of a judge's appointment, and makes it clear that the PiS-controlled Constitutional Tribunal carries more weight than the CJEU.

That set off a wave of complaints from the political opposition and many judges.

The country's Supreme Court issued a statement earlier this week condemning the legislation — saying it was similar in intent to the martial law decree passed by the communists in 1981 to crush the Solidarity labor union — and accusing the government of trying to take control of the court before May's presidential election.

The court's current head, Małgorzata Gersdorf, has been openly critical of the ruling party's legal changes. She is due to step down in April.

The court said the bill violates both Polish and EU law, and warned it would "lead the institutions of the European Union to begin procedures over the violations of obligations under the treaties and, in the longer term, the necessity of leaving the European Union."

“Democracy is dying in Poland and in Hungary” — Sophie in 't Veld, Dutch liberal MEP

If passed, the bill would add to the long list of disputes between Warsaw and Brussels over PiS's legal changes that have soured relations between one of the EU's largest countries and the rest of the bloc.

"The Commission continues to follow the situation in Poland closely," Commission spokesperson Christian Wigand said this week.

At a hearing in the European Parliament on Monday, many MEPs condemned the changes taking place in Poland, which were vociferously defended by lawmakers from PiS.

Didier Reynders, the justice commissioner, warned of a "chilling effect" on Polish judges, while Sophie in 't Veld, a Dutch liberal MEP, said: “Democracy is dying in Poland and in Hungary.”

Poland's ruling party has reacted furiously to any criticism of the legislation.

Prime Minister Mateusz Morawiecki warned on Tuesday of the danger of "legal chaos" caused by judges questioning the appointment and verdicts of other judges. "What serious European country could allow for something like that?" he asked.

President Andrzej Duda said of judges that "the level of lies of this grouping and of its hypocrisy stuns me."

The opposition is seizing on the storm provoked by the bill to try to galvanize public opinion against PiS.

On Wednesday evening, widespread protests took place under the banner: “Today judges, tomorrow you.”

“This is against the values which we all hold, against the values of the European Union,” Rafał Trzaskowski, the liberal mayor of Warsaw, told a crowd outside the Polish parliament in Warsaw.

Donald Tusk, the former Polish prime minister and European Council president who is now head of the European People's Party, tweeted earlier: "Everywhere authorities attack independent courts, in the end it turns out that it's about the same thing: to be able to steal without consequences. The only way to stop that is through the determined resistance of the people."

However, attempts by the opposition to block Law and Justice over the past four years largely failed, and the ruling party remains overwhelmingly popular in opinion polls.

Lili Bayer contributed reporting.

This article has been updated with Wednesday evening's protests.