Spain appears to be heading for political gridlock after inconclusive national elections left parties on the right and left without a clear path towards forging a new government.

The conservative Popular Party won the election but fell short of its hopes of scoring a much bigger victory and forcing the removal of Socialist Prime Minister Pedro Sanchez.

Instead, the party led by candidate Alberto Nunez Feijoo performed below expectations of most of the campaign polls.

Spain Election
Popular Party leader Alberto Nunez Feijoo (Manu Fernandez/AP)

Even though Mr Sanchez’s Socialists finished in second place, they and their allied parties celebrated the outcome like a victory since their combined forces gained slightly more seats than the PP and the far-right.

The bloc that could support Mr Sanchez totalled 172 seats and the right bloc behind Mr Feijoo had 170.

“It was a Pyrrhic victory for the Popular Party, which is unable to form a government,” said political analyst Veronica Fumanal, adding the conservatives will have to link up with the far-right, and even then it will not be enough. “I see a deadlock scenario in the parliament.”

The closer-than-expected election is likely to produce weeks of political jockeying and uncertainty over the country’s future leadership. The next prime minister will only be voted on once legislators are installed in the new Congress of Deputies.

But the chances of Mr Sanchez picking up the support of 176 legislators — the absolute majority in the Madrid-based parliament — needed to form a government are not great either.

Spain Election
Pedro Sanchez (Emilio Morenatti/AP)

The divided result has made the hardline Catalan separatist party Junts (Together) Mr Sanchez’s potential kingmaker. If Junts asks for a referendum on independence for Catalonia, that would be likely to be too costly a price for Mr Sanchez to pay.

“We won’t make Pedro Sanchez PM in exchange for nothing,” Miriam Nogueras of Junts said after the results.

With 98% of votes counted, PP is on course for 136 seats. Even the 33 seats that the far-right Vox is poised to get and the one seat for a minor party that aligns itself with the PP would still leave it far from its goal of a major victory.

The Socialists are set to take 122 seats, two more than they had, but Mr Sanchez is likely to be able to call on the 31 seats of its junior coalition partner Sumar (Joining Forces) and several smaller forces to at least total more than the right-wing parties.

“Spain and all the citizens who have voted have made themselves clear. The backward-looking bloc that wanted to undo all that we have done has failed,” Mr Sachez told a jubilant crowd at Socialists’ headquarters in Madrid.

After his party took a beating in regional and local elections in May, he could have waited until December to face a national vote, but he stunned his rivals by moving the vote in hopes of gaining a bigger boost from his supporters.