Protesters hold a flag with the Solidarity trade union logo and shout slogans outside the senate building in Warsaw on July 21. Parliament is debating a contentious bill that gives politicians influence on the nation's top court. (Alik Keplicz/AP)

The Polish Parliament moved this week to expand political control of the judiciary, threatening a showdown with the European Union over legislation that Brussels has condemned as an assault on democracy and the rule of law. 

Proposed by the ruling Law and Justice party, the measure would remove current members of the Supreme Court, except those handpicked by the justice minister, and grant the governing party power over future ­appointments. The proposal cleared the lower chamber Thursday and was passed by the Senate late Friday. Its proponents were undeterred by the finding of lawyers advising the upper chamber that parts of the measure would be unconstitutional. The body with the authority to invalidate it, the Constitutional Tribunal, has been filled with government loyalists.

The U.S. State Department sounded an alarm about the legislation, warning in a Friday statement that the bill appeared “to undermine judicial independence and weaken the rule of law in Poland.” In a recent speech in Warsaw, President Trump praised Poland as a model for the West.  

As the Senate debated the measure late Friday before voting 55 to 23, protesters descended on the government building in central Warsaw, carrying candles and white roses and singing the national anthem. Mass demonstrations have unfolded across Poland for the past week.

From a window high up in the building, a former leader of the Senate, Bogdan Borusewicz, called out encouragement to protesters, saying, “You are giving us strength.”

Below, a former head of the Constitutional Tribunal, Andrzej Rzeplinski, told the crowd, which briefly fell silent, “We were guarding the constitution for you.” Drawing on Poland’s history of resistance under communism, he urged: “Protest peacefully like we did the last 45 years.”

“I’m terrified of not living in a free country,” said Paulina Wilk, a 37-year-old writer. “Fair elections will be next to go.”

Popular protest has again become urgent, government critics say, as opposition lawmakers lack means to impede the Law and Justice party, which controls Parliament.

The threat to the independence of the Supreme Court is the latest maneuver by the right-wing party, which gained power in 2015, to bring the judiciary under its control. Another measure it has advanced would disband an independent body that selects new judges, transferring that power to Parliament.

The measures require the signature of President Andrzej Duda, whose veto is becoming the last hope for opponents of the legislation. Still aligned with Law and Justice despite formally separating himself to become president, Duda sought to moderate the changes but is expected to fall in line with the party. He is closely tied to Jarosław Kaczynski, leader of Law and Justice and architect of the politicization of the courts. 

The government has also clamped down on state media and moved to restrict the right to democratic assembly. But c ritics say the judicial reorganization is the clearest sign yet of the populist, anti-democratic ­direction in which Law and Justice is taking Poland, a country that overthrew communism in one of the earliest and most fervent democratic movements that swept Europe in 1989. 

Jan Rulewski, a senator and former activist with the labor union that led the independence movement, Solidarity, wore prison clothes to the chamber to announce his opposition to the measure. “Poland is becoming a penitentiary,” he said.

Law and Justice says the measures are long-overdue judicial reforms purging communist influence from the courts. TVP Info, a public broadcaster that has become a mouthpiece of the state, hailed “the end of post-communism in Poland.” Marek Pek, a Law and Justice senator, said the aim is to restore the proper balance of powers.

E.U. officials disagree, and if the Supreme Court measure goes into effect, it could trigger an effort in Brussels to strip Poland of its voting rights in decisions of the bloc — a never-invoked nuclear option.

“The rule of law is one of the values on which our union is founded and which defines our union,” European Commission Vice President Frans Timmermans told reporters in Brussels.

But any move to deprive Polish leaders of their voice in E.U. decisions would require the unanimous consent of the other 27 leaders, and Hungarian Prime Minister Viktor Orban has said he does not support the idea.

Klaudia Kocimska and Magdalena Foremska in Warsaw and Michael Birnbaum in Brussels contributed to this report.