MADRID (AP) — Spain’s top court has handed down a ruling preventing the upper house of Parliament from debating and voting on an amendment to the country’s penal code — an unprecedented interference in the legislature that foreshadows potential political turmoil for the leftist coalition government heading into election year.

The Constitutional Court ended a nine-hour debate Monday by accepting an appeal by the main right-wing opposition Popular Party to halt the passage through Parliament of a reform on how judges are elected to certain judicial bodies — including the Constitutional Court itself.

Socialist Prime Minister Pedro Sánchez lashed out at the Popular Party, saying the decision was unprecedented in 44 years of Spanish democracy and also in European terms as it has paralyzed Parliament and affected the renewal of the Constitutional Court, which is demanded by the country’s Constitution.

He said the Popular Party’s “aim was to retain by spurious means power that the citizens denied them in elections.”

He said he understood many people’s indignation over the issue but called for “serenity” and promised the government would work to break the judicial deadlock “with whatever measures were necessary.”

Critics see the Popular Party appeal as an attack on the Parliament’s sovereignty and a move by it to avoid losing influence in the court. The Popular Party, in turn, accused the government of trying to take control of the court in an underhand manner by including the reform in an express package that would have limited debate on the matter.

The decision, the first of its type in Spain’s four-decade-old democracy, could have untold effects on future legislation procedures and possibly cause Socialist Prime Minister Pedro Sánchez headaches as he seeks reelection in 2023.

The Constitutional Court frequently accepts appeals to stall and study legislation that has already been passed. It currently has appeals by the Popular Party against several key laws on its books, including on abortion, euthanasia and education. But never has it intervened in the process before approval.

“We´re facing a very grave situation, a blow to democracy,” Jaume Asens, parliamentary spokesman for Unidas Podemos (United We Can) — the minority party in the governing coalition — told Spanish National Television on Tuesday.

At stake is the perceived political alignment of the country’s judiciary bodies, although nominally they are independent and neutral.

Both the top court and General Council of the Judiciary, which supervises judges, have long been seen as having a conservative tilt. The renewal of the council has been deadlocked for the past four years due to a lack of consensus between the Socialist Party and the Popular Party. Both the ruling and main opposition parties, as well as Parliament, have a say in naming judges.

The council’s stalemate, in turn, affects the periodic replacement of judges on the Constitutional Court as it gets to select two judges to the court, but the council has so far not agreed on its selection.

That deadlock has kept the council and the Constitutional Court in the hands of majorities considered to be conservative.

The two leftist parties in government decided to push the judicial reform as a means of breaking the deadlock in the appointment of new members to judicial bodies, but the Popular Party balked at the idea.

In the case of the Constitutional Court, the terms in office of four of its judges, including its president, expired months ago and two of them stood to lose their posts if replacements were agreed on under the reform.

The reform was debated and passed by an ample majority in the lower house last week and had due to be approved with ease by the upper house — the Senate — on Thursday.