A fiercely secessionist leader was elected president of the wealthy region of Catalonia on Sunday thanks to a last-minute show of unity, giving fresh impetus to attempts to break away from Spain after months of infighting.

The appointment of Carles Puigdemont, just hours before a deadline which would have forced fresh regional elections, drew an immediate rebuke from Spanish Prime Minister Mariano Rajoy.

“The government won’t allow a single act that could harm the unity and sovereignty of Spain,” Rajoy warned in a live televised appearance in Madrid.

Rajoy’s remarks came after Catalonia’s pro-independence faction that won regional parliamentary elections in September finally came to an agreement this weekend over who should lead the new local government.

The sticking point had been Artur Mas, the incumbent, separatist regional president whom the far-left CUP — part of the secessionist faction that topped the polls — rejected over his support for austerity and corruption scandals linked to his party.

In a surprise move Mas agreed to step aside on Saturday, naming the relatively unknown politician Puigdemont as his successor and sparing Catalonia its fourth set of elections since 2010.

Puigdemont, the 53-year-old mayor of Girona who comes from a fervently pro-independence family, will now appoint his cabinet.

“We need… to start the process to set up an independent state in Catalonia,” Puigdemont said in a speech to the northeastern region’s parliament ahead of the vote.

Puigdemont, a baker’s son, has never hidden his separatist tendencies, not even when he joined Mas’s CDC party in 1980 at a time when it merely wanted to negotiate greater autonomy for Catalonia — far from the idea of breaking away from Spain.

– ‘Power vacuum in Madrid’ –

Despite having to step aside, Mas hailed the last-ditch agreement, telling his party on Sunday that in Madrid “all the alarm bells started ringing again”.

“In the past few weeks (in Madrid), they were saying enthusiastically that Catalonia was sinking, they were so enthusiastic that they had started to relax,” he told members of his CDC party.

The formation of a Catalan government stands in stark contrast to the situation in Madrid, where the national government is in limbo following inconclusive December polls.

Rajoy’s conservative Popular Party (PP) came top in the December 20 elections but lost its absolute majority, leaving him struggling to form a coalition government as other parties refuse to support him.

“The (separatist) coalition is profiting from the power vacuum in Madrid,” headlined online daily El Espanol on Sunday.

So far the PP’s traditional Socialist rivals PSOE, who came second in the elections, have refused to back the incumbent Prime Minister.

But ironically, the newly-reached separatist deal may put pressure on the PSOE to stand united with the PP over its opposition to Catalonia breaking away from Spain.

“We reiterate our support for the caretaker government to enforce the law and defend the Constitution,” Antonio Hernando, a Socialist spokesman, told reporters Sunday.

And Fernando Martinez-Maillo of the PP stressed that there was “no better way to confront secessionism than to see the Popular Party and the Socialist party join forces”.

– Support for referendum –

One of Spain’s 17 semi-autonomous regions with its own language and customs, Catalonia already enjoys a large degree of freedom in education, health and policing.

But fed up after years of demands for greater autonomy on the taxation front — complaining it pays more to Madrid than it gets back — the region veered towards separatism.

Polls show most in the 7.5-million-strong region support staging a Scotland-style referendum on independence — which Rajoy has categorically refused to allow — but in fact are divided over whether to make the break from Spain.

In November, separatist lawmakers passed a motion in parliament breaking from Spain and calling for complete independence in 18 months.

The move was later ruled illegal by Spain’s Constitutional Court, but Catalonia’s secessionist lawmakers quickly rose up in defiance, saying the resolution was here to stay.