SPAIN was in turmoil yesterday after Europe’s top court sensationally ruled that a Catalan independence leader jailed after the October 2017 referendum should have parliamentary immunity from the time he was elected.

The European Court of Justice (ECJ) found that Oriol Junqueras, who leads the Republic Left of Catalonia (ERC) and was Catalonia’s vice-president at the time of the poll, had the right to immunity because he was elected to the European Parliament in May, five months before he was sentenced to 13 years in prison.

It said people like him who are elected EU parliamentarians “enjoy, from the moment the results are declared, the immunity” to travel to and take part in parliamentary sessions. He was already in pre-trial detention when he won a European seat.

READ MORE: Sanchez and Torra speak for first time since Catalan leaders jailed

However, Spanish authorities did not release him from prison to take up his seat, arguing that MEPs only enjoyed immunity once a swearing-in process is concluded.

The National: The ECJ ruled that Oriol Junqueras must be releasedThe ECJ ruled that Oriol Junqueras must be released

The Spanish electoral commission later ruled his seat vacant and suspended his parliamentary privileges.

For his part, Junqueras argued that his immunity came into effect from the moment the official vote results were declared. The ECJ agreed, ruling: “A person who is elected to the European Parliament acquires the status of MEP as a result of and from the time of the declaration of the election results, with the result that he enjoys the immunities guaranteed by Article 9 of the Protocol.”

Yesterday, Junqueras tweeted: “Justice has come from Europe. Our rights and those of 2,000,000 citizens who voted for us have been violated. Annulment of the sentence and freedom for all! Persist as we did!”

David Sassoli, president of the European Parliament, said that Spain should obey the ruling: “The ECJ found that a person elected acquires the status of member of the @Europarl_EN and therefore enjoys immunity. I call upon the competent Spanish authorities to align with the ruling.”

READ MORE: Catalan president in court over 'partisan' yellow ribbons

It took only 90 minutes for Spain’s Supreme Court to react, saying in a statement: “The court will study in depth the full contents of the ECJ ruling in response to questions raised by … a July 1 interlocutory hearing on the immunity scope of Oriol Junqueras, when that person was in jail. Whatever comes from the result will be agreed.”

While Junqueras waits in prison, former Catalan president Carles Puigdemont and ex-minister Toni Comin, who were also elected MEPs in May but who are exiled in Belgium, must also wait to find out Spain’s next move. A Brussels court said earlier this week it would await the outcome of his European case before deciding whether to extradite the pair under a European Arrest Warrant (EAW) issued by Spain.

The National: Carles Puigdemont is in exile in BrusselsCarles Puigdemont is in exile in Brussels

Puigdemont welcomed the ECJ ruling on social media: “The ECJ defends the same criteria that we have defended against the European Parliament and the Spanish authorities, which have sought to alter the functioning of European democracy ... Democracy, the vote of the people, has won against authoritarian forces ... See you (soon) at the @Europarl_EN.”

The ERC called for the immediate release of Junqueras, with its coordinator and vice-president Pere Aragones, saying: “Today’s is a historic victory for Junqueras, the constituents and European citizens. The Junqueras doctrine has been constituted to guarantee the rights of European voters.”

Scots lawyer Aamer Anwar, who has been fighting an EAW for St Andrews-based former Catalan education minister Clara Ponsati, told The National: “The decision by the ECJ is a complete humiliation of Spain’s judicial and political system that masquerades as a democracy – the judgment has a wider impact on the question of immunity for Puigdemont [and] Comin who were also elected as MEPs but unlawfully denied their seats ... Ultimately it must also have an impact on the extradition of Clara Ponsati, once Brexit takes place and Spain receives extra seats in the European Parliament.

READ MORE: Spanish PMs cited to give evidence in Scottish court against Clara Ponsati

“Theoretically, Clara would become a MEP as she was third on the list.

“The issue for Spain is whether it practises the rule of law or wants to act as a ‘petulant rogue state’ within the heart of Europe.”

Yesterday's ECJ ruling came just hours after Spanish riot police used riot batons and rubber bullets against unarmed independence supporters who had gathered outside the Nou Camp in Barcelona, where the home side were playing Real Madrid. More than 50 people were injured and 10 arrested.