BERLIN — Europe’s top court ordered Poland’s government on Friday to immediately halt implementation of a controversial law designed to force nearly two dozen of the nation’s Supreme Court justices into early retirement.

The surprise decision by the European Court of Justice (ECJ) sets up a potential clash between European authorities and the right-wing Polish government, which has been accused of subverting the rule of law by attempting to pack the Supreme Court with sympathetic judges. 

Polish officials had earlier suggested they might defy the ECJ’s will if the court sought to get involved in what the government sees as a purely domestic matter. On Friday, they offered mixed reactions to the decision, insisting they will abide by European law while maintaining that the change to the retirement age cannot be reversed. 

Social video showed protests opposing constitutional changes to the court system in July in Warsaw and Wroclaw, Poland. (The Washington Post)

Polish judges, meanwhile, were jubilant at the European intervention, which had been regarded as the last chance to keep the country’s judiciary independent.

“This ruling has fundamental importance,” said Monika Frackowiak, a Polish district court judge and member of Iusticia, the country’s largest judicial association. “We hope it will somehow stop this process of demolishing the judiciary.” 

The decision was the latest twist in a drama that has gripped Poland — and troubled Europe — for more than a year. By injecting itself so forcefully, the ECJ has raised the stakes in the standoff between Polish and European authorities. Defiance by Poland would further escalate the debate over whether the country, and its ally Hungary, are fundamentally out of step with European values.

Critics of Poland’s ruling Law and Justice party regard implementation of the retirement law as the last major stage in a calculated plan by the government to commandeer the nation’s judicial system. Other elements of the system — including the Constitutional Tribunal and the National Council of the Judiciary — have already fallen under the ruling party’s sway. 

Under the law, which went into force in July, 28 Supreme Court justices — including the chief justice — were forced from the bench because they had hit the new mandatory retirement age of 65, down from 70. Five had since been reinstated by Poland’s president. 

Friday’s decision is a temporary one, with the Luxembourg-based ECJ yet to rule on whether Poland’s change to the retirement age violates European law. 

But the ruling requires Poland’s government to freeze a process that had been moving quickly ahead, with authorities rushing in recent weeks to appoint new judges with little apparent vetting.

In announcing the decision, the ECJ warned of possible “serious and irreparable damage” if the retirement-age law was implemented without a full legal review by the court. 

In addition to mandating the retirements, Poland is expanding its Supreme Court from 93 justices to 120. Combined, the two moves amount to “a profound and immediate change in the composition of the Supreme Court,” the ECJ said in its announcement. 

Frackowiak, the district court judge, said she believed the sweep and speed of the ECJ’s injunction were positive indications about the court’s ultimate intentions. “The direction has been set,” she said. “I can’t imagine they will go back.”

Following the Friday ruling, several recently retired Supreme Court justices announced they would be back to work by Monday. The chief justice, Malgorzata Gersdorf, has continued to show up for work in protest since July. Under the constitution, her term does not expire until 2020.

In an interview in her chambers last month, Gersdorf said the country was headed in “an extremely dangerous direction,” with the government seeking to snuff out judicial independence.

“They want to be able to use the improper, anti-democratic ­levers of power to advance their interests,” she said.

Friday’s ruling came in response to a petition by the European Commission, the European Union’s executive arm, which has been critical of Polish government moves that it regards as a betrayal of democratic values.

The commission last December triggered what are known as Article 7 proceedings against Poland, a process that could end with the loss of the country’s voting rights in meetings of European leaders.

Poland’s prime minister, Mateusz Morawiecki, said the ECJ’s ruling would need to be studied before the government could officially respond. A ruling party spokeswoman, Beata Mazurek, meanwhile, wrote on Twitter that Poland “is a member of the E.U. and will act in accordance with the current E.U. law.”

But the chief of staff to President Andrzej Duda suggested there may be limits to Poland’s willingness to adhere to the decision. “It’s impossible for law to work in reverse,” said Krzysztof Szczerski, whose boss has ultimate authority to appoint new judges.

Failure to comply with the ruling could subject Poland to hefty fines.

Polish officials have argued that an overhaul of the judiciary is needed to purge the courts of communist elements left over from before the country’s turn to democracy in 1989. But independent experts scoff at that explanation, noting that judges were long ago subject to a rigorous process designed to weed out those guided by politics, not the law.

Poland’s judges have been nearly unanimous in opposing this year’s changes and have largely boycotted the process for selecting new justices. 

Friday’s ruling was welcomed by Guy Verhofstadt, leader of the Liberal faction in the European Parliament, who called it “an important step.” 

“The Polish government crossed a red line by attempting to politicize Poland’s Supreme Court,” Verhofstadt said in a statement. “We can only preserve the integrity of E.U. legal order if all member states fully abide by ECJ decisions and rulings.”

Quentin Aries in Brussels and Magdalena Foremska in Warsaw contributed to this report.