Spain’s ruling Socialists won the largest share of the vote in Sunday’s general elections but failed to secure enough seats to form a government, as the far-right party staged a stunning breakthrough to become the third force in the national parliament.

As weary voters headed to the polls for the fourth time in as many years, parties on the left and the right failed to gain enough combined seats to break the political deadlock which has plagued the country since 2015.

With 99 per cent of votes cast, the acting centre-left government won 28.1 per cent of the vote but lost three seats, falling from 123 to 120, and coming well short of the 176 needed for a majority in the 350-seat lower house.

Vox, the far-right party which burst on to the national stage only six months ago when it won 24 seats in inconclusive elections in April, more than doubled the number of its MPs to 52.

Santiago Abascal, the leader of Vox, said he wanted to build a “patriotic alternative” for the country as he was greeted by cheering crowds in Madrid.

Spanish incumbent prime minister and Socialist Party (PSOE) candidate for re-election, Pedro Sanchez, celebrates his victory during the election night in Madrid (AFP via Getty Images)

The secessionist crisis in Catalonia had fuelled support for Vox in the run up to the election.

There were mass protests and street violence for three weeks last month after nine separatist leaders were sentenced to up to 13 years in prison for sedition.

The mainstream conservative Popular Party (PP), which suffered a historic reverse in the last poll when it won only 66 seats, saw its share of the vote surge, winning 87 seats.

Vox and the PP benefited from the collapse of the liberal Ciudadanos (Citizens), which won only 10 seats, a dramatic fall from the last election when it came in third place with 57 seats.

After the last elections, Ciudadanos had at first rejected a coalition with the Socialists, then appeared to entertain the possibility of an alliance, raising voters’ suspicions it had lost its way.

The Socialists have the best chance of regaining power but will need to forge a fragile alliance with the far-left Unidos Podemos (United We Can) party, which saw its MPs fall from 42 to 35, a new left-wing party Mas País (More Country), smaller regional parties and separatist parties Catalan Republican Left (ERC) or Together for Catalonia (JxCat).

Such an alliance may prove risky. The separatists withdrew their support from the Socialist government’s budget in February, prompting the last elections.

Pablo Iglesias, the leader of UP, hinted his party would be prepared to offer help to Spain’s Socialist prime minister Pedro Sánchez to form a government.

Mr Sanchez said that he would call other party leaders starting on Monday to tackle a political stalemate, adding that he hoped to form a stable, “progressive” government.

Members of an electoral commission count voting ballots during Spain’s general election at a polling station in Madrid, Spain (REUTERS)

“We are going to offer a helping hand to the Socialist party. We think that combining the courage of United We Can and the experience of the Socialist party we can convert our country into a reference point for social policies,” he said as he cast his vote.

“We are going to leave behind the reproaches.”

Attempts to form a left-wing coalition between the two parties in July ended in failure, with the party leaders trading bitter reproaches.

The surge in support for Vox has been seen as a protest by voters over the perceived failure by the Socialist government to deal with weeks of riots in Catalonia.

“I have always voted for traditionally conservative PP, but this time I voted for Vox. I am fed up that the government has not cracked down on what has happened in Catalonia. They seem scared,” said Juan Goytisolo, 27, an economist, from Malaga.

In Catalonia, others felt anger over the jailing of secessionist leaders and backed separatist parties.

Supporters of Spain’s far-right party VOX react as they hold flags during Spain’s general election, outside the party headquarters in Madrid, Spain (REUTERS)

“I don’t support independence but this time I voted for ERC. These sentences were outrageous,” said Dolores López, 53, a software engineer from Barcelona.

Pablo Simón, a political expert at the Carlos III University in Madrid, said: “There are probably only two options to form a government: the Socialists could team up with Podemos with the help of smaller parties and the separatist parties. Or the parties on the right could abstain and allow the Socialists to form a minority government.

“It seems the second option is less likely because parties on the right, like the PP would demand something in return for this from Sánchez.”

He said if no deal could be reached to break the stalemate, Spain could be heading for another election after Christmas.

Two people died while casting their vote while a man was arrested with a gun at a polling station in Catalonia.

An elderly woman died while casting her vote in Granada, southern Spain and an 87-year-old man fell ill and died in a voting station in the Basque Country in the north west of the country. Medical services said both suffered heart attacks.