The fate of Catalonia has hung in the balance since regional polls in September, in which secessionist groups came out top although no one party managed to gain an absolute majority.
But the deadlock was broken on Saturday when regional president Artur Mas, from the "Together for Yes" alliance, agreed to step aside to avoid triggering fresh elections.
The far-left CUP party had refused for more than three months to back the leader because of his support for austerity measures and his party's links to corruption scandals.
Mas named Carles Puigdemont as his successor, paving the way for a separatist coalition government which aims to declare independence from Spain within 18 months.
On Sunday evening, separatist members of the regional parliament will confirm the selection of Puigdemont, a Catalan-language journalist from Mas's party.
The 53-year-old mayor of Girone, which lies some 100 kilometres (60 miles) north of Barcelona, will then appoint his cabinet.
If a deal had not been reached by midnight on Sunday, Mas would have had to call fresh elections in Catalonia, which would have come as a major setback for the independence drive.
"Our project is solid and working in the right direction," Puigdemont tweeted after the last-minute agreement, as the separatists gather their forces to take the fight back to Madrid.
Spain's government is currently in limbo after legislative elections in December in which Prime Minister Mariano Rajoy's conservative Popular Party (PP) came top but lost its absolute majority.
So far both the PP's traditional Socialist rivals (PSOE), who came second in the elections, and upstart anti-austerity party Podemos have refused to support him.
But, faced with the prospect of secession by Spain's richest region, Rajoy insisted Saturday that the country's next government should have "an ample parliamentary base with the stability and capacity to face the separatist challenge".
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 most people in Catalonia, Spain's richest region with a population of 7.5 million, 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 to create a distinct social security system and treasury, with a view to completing independence in a year and a half.
Rajoy immediately filed suit against the move in the Constitutional Court, which annulled the independence motion last month.