Spain's Socialist Party has lost its first attempt to form a government, falling far short of the parliamentary votes needed ahead of a second ballot scheduled for Friday.

The Socialists, led by Pedro Sanchez, got just 130 votes, with 219 against and one abstention. The conservative Popular Party, led by acting Prime Minister Mariano Rajoy, and the far-left newcomer Podemos party joined together along with several small regional parties to deny Mr Sanchez's attempt at becoming prime minister.

The vote came after an inconclusive December 20 election that saw the nation's traditional two-party system shattered with the entry of Podemos and another upstart party, the business-friendly Ciudadanos.

Podemos and Ciudadanos got third and fourth place because of voter outrage over high Spanish unemployment, unpopular austerity measures invoked by the Popular Party during its 2011-2015 rule and corruption scandals hitting the Popular and Socialist parties.

Mr Sanchez needed at least 176 votes to form a government but only received his party's 90 votes plus 40 from Ciudadanos.

Mr Rajoy had earlier labelled Mr Sanchez's plans to form a government as a joke and said all of his party's 123 deputies would vote against the Socialists, who came in second in the election. Mr Rajoy's party came in first but fell far short of winning the parliamentary majority it had previously.

Pablo Iglesias, the leader of Podemos with 69 seats, said his parliamentarians voted against Mr Sanchez because they did not believe the Socialists would lead a bonafide leftist government.

Mr Sanchez has another chance on Friday in a second parliamentary voting round with different winning rules in which he must get more votes for him than against him. That is a lower bar which allows parties to abstain, letting a rival into power in return for concessions.

Mr Rajoy decided in January not to try to form a government because he lacked support.

If Mr Sanchez fails to win Friday's vote, parliament has two more months to try to choose a government or new elections will be called for June 26.

A governing alliance of parties excluding the first-place winner has never happened nationally in Spain.

But it recently happened in neighbouring Portugal and has a precedent in Spain at the regional and local governing level.