By Sonya Dowsett and Sam Edwards
BARCELONA (Reuters) - Catalonia's separatists look set to regain power in the wealthy Spanish region after local elections on Thursday, deepening the nation's political crisis in a sharp rebuke to Prime Minister Mariano Rajoy and European Union leaders who backed him.
With nearly all votes counted, separatist parties won a slim majority in Catalan parliament, a result that promises to prolong political tensions which have damaged Spain's economy and prompted a business exodus from the region.
Rajoy, who called the elections after sacking the previous secessionist government, had hoped Catalonia's "silent majority" would deal separatism a decisive blow in what was a de facto independence referendum, but his hard line backfired.
The unexpected result sets the stage for the return to power of deposed Catalan president Carles Puigdemont who campaigned from self-exile in Brussels. State prosecutors accuse him of sedition, and he faces arrest if he were to return home.
"Either Rajoy changes his recipe or we change the country," Puigdemont, said in a televised speech. He was flanked by four former cabinet members that fled with him.
At jubilant pro-independence rallies around Barcelona, supporters chanted "President Puigdemont" and unfurled giant red-and-yellow Catalan flags as the results came in.
Puigdemont's spokesman told Reuters in a text message: "We are the comeback kids."
The result unnerved global markets, contributing to a softer euro and subdued sentiment in stock markets. Opinion polls had predicted secessionists to fall short of a majority.
More than 3,100 firms have moved their legal headquarters outside Catalonia, concerned that the indebted region, which accounts for a fifth of the national economy, could split from Spain and tumble out of the EU and the euro zone by default.
Spain has trimmed its growth forecasts for next year, and official data shows foreign direct investment in Catalonia fell 75 percent in the third quarter from a year earlier, dragging down national investment.
The EU's major powers, Germany and France, have backed Rajoy's stance despite some criticism of his methods at times.
On Oct. 1, when Catalonia staged an independence referendum, Spain declared it unconstitutional and national police used tear gas and batons to prevent some Catalans from voting.
When Catalan parliament declared independence after the referendum, Rajoy invoked constitutional powers to impose direct rule from Madrid on the region. He has said he would rescind direct rule regardless of the election result, but could re-impose it if a new government again pursued secession.
There was no immediate comment from Rajoy after the election results.
HEADACHE FOR BRUSSELS
The narrow victory for Puigdemont's secessionist camp presents a fresh headache for the EU, which had defended the Spanish judiciary's pursuit of separatist leaders on grounds that they had violated Spain's constitution.
Puigdemont's attempts to gain international support in Brussels have come to nothing so far. He has called the EU a "club of decadent countries" for declining to mediate a solution.
Separatist parties won 70 seats out of 135, with Puigdemont's Junts Per Catalunya (Together for Catalonia) party retaining its position as the largest separatist force.
Unionist party Ciudadanos (Citizens) won the most votes, but other unionist forces -- Rajoy's People's Party and the Socialist Party -- registered a dismal performance.
"It's a bitter victory," said Paloma Morales, a 27-year-old student at a Ciudadanos rally.
"It means four more years of misery."
Analysts said the ball was back in Rajoy's court.
"What this shows is that the problem for Madrid remains and the secession movement is not going to go away," said Antonio Barroso, deputy director of research at London-based research firm Teneo Intelligence.
Turnout on Thursday reached a record high with over 83 percent of eligible Catalans voting.
Puigdemont's former deputy, Oriol Junqueras, and several other Catalan politicians are in prison, along with the leaders of the two main separatist grassroots movements.
(Additional reporting by Jesus Aguado in Madrid and Robert-Jan Bartunek in Brussels; Writing by Angus Berwick and Ingrid Melander; Editing by Julien Toyer, Jeremy Gaunt and Mark Bendeich)