Catalonia’s parliament has voted in a hardline separatist leader, bringing an end to seven months of direct rule from Madrid.

Quim Torra, a former lawyer who went on to lead a prominent pro-secession group, was voted in by 66 votes in favour to 65 against.

He vowed to build an independent Catalan republic by working under the leadership of his predecessor, Carles Puigdemont, who is currently in Germany fighting extradition to Spain.

He is wanted for allegedly using public funds and orchestrating an “insurrection” to get Catalonia to break away from Spain.

Immediately after his election, Mr Torra said one of the goals of his new government would be to reinstate Mr Puigdemont as “the legitimate president” of Catalonia.

The Spanish government removed Mr Puigdemont and his cabinet from office after the regional parliament passed an illegal declaration of independence in October.

“Our president is Carles Puigdemont, and we will be faithful to the mandate of October ... to build an independent state in the form of a republic,” Mr Torra told the chamber, which is based in Barcelona.

Mr Torra has also promised to create a “state council in exile” and vowed to establish a constituent assembly to write the constitution for a new Catalan republic.

Carles Puigdemont says he cannot return to Catalonia because Spain is intent on 'vengeance'

“Everybody will win rights with the republic,” Mr Torra said in a speech before the vote. “Nobody will lose rights. The republic is for everybody, no matter what they vote.”

The Catalan separatist movement has caused the worst political and institutional crisis in Spain in decades.

Central authorities have been ruling Catalonia directly from Madrid since the regional government led by Mr Puigdemont relied on the results of an outlawed 1 October referendum to declare unilateral independence from Spain.

The national government has fired dozens of civil servants and closed a network of overseas offices that sought investments in Catalonia but also functioned as “diplomatic delegations” to bolster support for independence.

The unprecedented Spanish takeover is set to end when Mr Torra is sworn in along with a new Catalan Cabinet.

Catalonia election: in pictures Show all 9 1 /9 Catalonia election: in pictures Catalonia election: in pictures People react to results in Catalonia's regional elections at a gathering of the Catalan National Assembly REUTERS Catalonia election: in pictures Ousted Catalan leader Carles Puigdemont and former Catalan Health Minister Antoni Comin, left, gesture during a press conference Rex Features Catalonia election: in pictures Center-right party Ciudadanos (Citizens) candidate Ines Arrimadas (C) and the rest of candidates and party members celebrate their polls results AFP/Getty Images Catalonia election: in pictures Suporters of Ciudadanos party celebrate the results EPA Catalonia election: in pictures Former Catalan regional minister Jordi Turull (C), candidate of Catalan pro-independence party Junts per Catalunya, and former Catalan regional minister Josep Rull, candidate of Junts per Catalunya celebrate the results Rex Features Catalonia election: in pictures Catalan independence supporters celebrate AP Catalonia election: in pictures Candidate of Ciudadanos party to the Catalan regional elections, Ines Arrimadas (C), next to the party leader, Albert Rivera (behind), delivers her speech as they celebrate the results EPA Catalonia election: in pictures Catalan independence supporters celebrate at the Catalan National Assembly headquarters after results of the regional elections in Barcelona AP Catalonia election: in pictures Junts Per Catalunya supporters celebrate following the Catalan regional election Getty Images

However, Spanish authorities have warned the national government could reassert its authority if the new regional government breaks the law again.

Spain’s prime minister, Mariano Rajoy, said he didn’t like what he had heard during the debate in the Catalan assembly. He said his judgment on Mr Torra’s appointment will depend on the new leader's actions.

“We will bet on understanding and agreement in looking at the future,” Mr Rajoy said. “But I say this, and I mean it: I will make sure that the law, the Spanish Constitution and the rest of the legal system, are obeyed.”