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 Sánchez.

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

Even though Sánchez’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.

READ MORE: Spain election will indicate the health of democracy in Europe

The bloc that could support Sánchez totalled 172 seats and the right bloc behind 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 Sánchez picking up the support of 176 legislators — the absolute majority in the Madrid-based parliament — needed to form a government are not great either.

The divided result has made the Catalan independence party Junts (Together) Sánchez's potential kingmaker.

“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 Sánchez 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.

READ MORE: Scottish Government in 'urgent' talks to change Levelling Up Bill

“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,” Sánchez 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.