Spain's Socialist prime minister, Pedro Sanchez, emerged from inconclusive elections on Sunday with a strong chance to regain power, though he faces weeks or even months of negotiations to assemble a government from a deeply divided new parliament.
In one of the country's most hotly contested elections in decades, the rise of nationalist party Vox split the right-wing vote, echoing fragmented parliaments across Europe where traditional groups have ceded to anti-establishment upstarts.
Spaniards cast their votes in numbers close to record highs with campaigning dominated by national identity and cultural values like women's rights rather than the economy.
This is the third national election in four years, after the first two eroded the decades-long dominance of the two biggest parties, the Socialists and the conservative Popular Party.
Neither the rightist or the leftist political bloc held a clear majority, according to a tally of results from the Interior Ministry with 80 percent of votes counted.
By party, Sanchez's Socialists led with 132 seats in the 350-seat parliament. The mainstream conservative People's Party (PP) stood at 65 seats, centre-right Ciudadanos ('Citizens') at 57 seats, far-left Unidas Podemos at 42 and far-right Vox at 24.
Supporters gathered outside the Socialist headquarters in Madrid chanting 'Long live Spain' and 'Long live Socialism'.
There was speculation before the election about a possible coalition between the Socialists and Ciudadanos despite both parties' leaders ruling out any tie-up.
If they were to forge an alliance, their parliamentary majority would mean that Sanchez would not have to seek the support of regional parties favouring Catalan independence.
However he would face a large bloc of right-wing lawmakers.
"Vox is without a doubt one of the big winners of the night," said Narciso Michavila, the head of GAD3 pollsters, as the group's success looked set to hand the far-right a sizeable presence in parliament for the first time since the end of Francisco Franco's dictatorship of the 1970s.
The party, fierce opponents of the Catalan independence movement, had campaigned as guardians of Spanish history, customs and its survival as a nation.
Hundreds of people gathered outside Vox headquarters in Madrid for the vote count, waving Spanish flags and cheering.
In Spain, issues like mass immigration or euroscepticism that have dominated political discourse elsewhere have been eclipsed by the question of national unity and the threat posed by the Catalan independence movement.
"Catalonia has been the focal point of the campaign and it's what has made me vote for Vox. It's the party that most clearly fights against (Catalan) independence," said Alfonso Gomez, an unemployed 57-year-old, after voting in central Madrid.
The economy, one of the euro zone's star performers, took a back seat in campaigning across the political parties.
Spain had long been seen as resistant to the wave of populist nationalism spreading across much of Europe with many older voters remembering the military dictatorship of Franco that ended after his death in 1975.
"Many of us have voted to avoid the rise of the extreme right," said Anna, a 50-year-old care worker in Barcelona. She said she hadn’t voted in the last two national elections but decided to this time because she was concerned about Vox.