Catalonia's separatists on Saturday struck a last-minute agreement to form a new regional government that will work towards independence from Spain, with controversial secessionist leader Artur Mas stepping aside to seal the deal.
His decision brings an end to more than three months of deadlock between Mas' "Together for Yes" secessionist alliance and the more radical, far-left separatist CUP party that together hold a majority in the Catalan parliament.
"This is not an easy decision, but it is a coherent decision," Mas told a press conference, saying he did what was necessary to save the independence drive in the wealthy northeast region of 7.5 million.
"I am stepping aside and will not be standing as a Together for Yes candidate for the re-election of president of the regional government," Mas said, naming Girona mayor Carles Puigdemont as his replacement.
Together for Yes won 62 seats in the 135-seat parliament in regional elections in September -- but were unable to form a government with the CUP, which held a crucial extra 10 seats, due to bitter disagreement over Mas.
The leftist party refused to give Mas its backing, resenting the austerity measures he implemented and corruption scandals linked to his party.
If a deal had not been reached by midnight on Sunday, Mas would have had to call fresh elections, which would have come as a major setback for the independence drive.
Just days ago, that had seemed inevitable, with Mas saying he was ready to call fresh elections as his CDC party -- part of Together for Yes -- refused to consider fielding a different candidate for the presidency.
Puigdemont, 53, is head of the association of pro-independence municipalities as well as mayor of the city of Girona, around a hundred kilometres north of Catalan capital Barcelona.
With its own language and customs, Catalonia already enjoys a large degree of freedom in education, health and policing.
But it wants more independence from the Spanish state, particularly where taxation is concerned, complaining it pays more to Madrid than it gets back.
Polls show that most Catalans support a referendum on independence but are divided over breaking from Spain.
A 2010 decision by Spain's Constitutional Court to water down a statute giving Catalonia more powers has added fuel to the fire and caused support for independence to rise.
In November, the separatists passed a motion in the Catalan parliament calling on the assembly to start drafting laws within 30 days to create a separate social security system and treasury, with a view to completing independence in 18 months.
But Spain's conservative Prime Minister Mariano Rajoy immediately filed suit against the move in the Constitutional Court, which annulled the independence motion last month.