Spanish Prime Minister Pedro Sanchez's Socialists have won snap elections without the necessary majority to govern solo in a fragmented political landscape marked by the far-right's entry into parliament.

The results raise the spectre of another period of instability for Spain, with Sanchez depending on alliances with hostile rivals in an environment that has soured since Catalonia's failed secession bid in 2017.

A significant development was the rise of the ultra-nationalist Vox party, which garnered just over 10 percent of the vote in a country that has had no far-right party to speak of since the death of dictator Francisco Franco in 1975.

Sanchez's Socialist Party (PSOE) got 123 lawmakers out of 350, or close to 29 percent of votes -- short of an absolute majority but much better than the 85 seats it got in 2016.

"The Socialists have won the general election and with it the future has won and the past has lost," he told cheering supporters from the balcony of the party's headquarters in Madrid, claiming victory late Sunday.

The big loser was the conservative Popular Party (PP), which bagged 66 seats compared to 137 in the previous election that saw it govern Spain with a minority government.

Possible alliances

Sanchez, who came to power in June after ousting conservative prime minister Mariano Rajoy in a no-confidence vote, could seek to forge alliances with far-left Podemos and smaller groupings like Catalan separatist parties, as he had done over the past 10 months.

He could also try to cosy up to centre-right Ciudadanos, which won 57 seats. Together, they would form an absolute majority but voters from both parties would likely frown on such a move.

"I hope Sanchez won't reach an agreement with Ciudadanos, I want a left-wing government," 51-year-old Esther Lopez, said at the Socialist Party headquarters, wearing earrings marked "PSOE."

Ciudadanos leader Albert Rivera, built his campaign on disparaging Sanchez, criticising his attempts to negotiate with Catalan separatist parties in a bid to ease a secession crisis in the northeastern region.

In an editorial on Monday, Madrid daily El Mundo called on Sanchez to "reach out to Rivera and consider forming a moderate government -- which would undoubtedly go down well in Europe -- to ensure the stability" of the country.

Far-right emergence

The crisis in Catalonia was precisely what fuelled Vox's meteoric rise from the outer margins of politics to the national scene, after gaining nearly 11 percent of votes in December regional polls in southern Andalusia.

Founded by Santiago Abascal, a disgruntled former PP member, it will now take 24 seats in the national parliament.

This is less than what opinion polls had predicted.

"I thought Vox would get way more votes, with this result Vox won't have any weight in parliament as no one supports them. We needed more seats," said Maria Bonilla Ortega, a 22-year-old philosophy student in central Madrid, a Spanish flag draped around her shoulders.

Abascal was more optimistic: "We can tell Spain with complete calm that Vox has come to stay," he told cheering supporters.

After a tense campaign, voter turnout was high at 75.76 percent, up from 66.48 percent in 2016, election authorities said.

Catalonia shadow

With a strong stance against feminism and illegal immigration, Vox stood out with ultra-nationalist rhetoric advocating the "defence of the Spanish nation to the end" and a hard line against separatists in Catalonia.

The region in northeastern Spain was the scene of a secession attempt in 2017 that sparked the country's biggest political crisis in decades and caused major concern in Europe.

The issue has continued to cast a pall over Spanish politics.

Sanchez was forced to call Sunday's elections after Catalan pro-independence lawmakers in the national parliament, angered at the trial of their leaders in Madrid, refused to give him the support he needed for his 2019 budget.

Right-wing parties for their part lambasted Sanchez, at the head of a minority government, for talking with separatists who still govern the region, accusing him of cosying up to those who tried to break up Spain.

That controversy is likely to continue as two Catalan separatist parties gained even more lawmakers in the national parliament than they did in 2016 -- up to 22 from 17.

The five separatists elected are in jail and currently being tried at Spain's Supreme Court.

In a sign of the impact the crisis had on voters, Dolores Palomo, a 48-year-old domestic worker, said she had always voted for the socialists but cast her ballot for Ciudadanos this time at a polling station in Hospitalet de Llobregat, near Barcelona.

The reason? Sanchez "is a puppet of the separatists," she said.