Acting prime minister Pedro Sanchez will keep working with all parties to avoid another election after failing to be confirmed prime minister, said acting Deputy Prime Minister Carmen Calvo.

"He will keep on working with the rest of political leaders so as to have a government and avoid a new election," Calvo told a weekly news briefing.

On Thursday, Sanchez lost a second parliamentary vote to be confirmed on the job after his party failed to secure a deal with the left-wing Podemos.

Spanish MPs rejected appointing Sanchez as prime minister in the first and second poll on Tuesday and Thursday.

Sanchez required an absolute majority from parliament in the first vote, however, in the second one, he only required a simple majority.

Read more: 'Podemos is asking for too much, too early,' political analyst tells Euronews

"A deal wasn't possible," Sanchez told MPs, before adding: "I want to be Spain's prime minister, but not at any cost." Sanchez strongly criticised the way Podemos and its leader Pablo Iglesias had conducted the talks.

Sanchez failed to strike a deal with Podemos leader Pablo Iglesias because they couldn't decide what role Podemos would play in a possible coalition government.

The Podemos leader said, however, that his party would still like to be part of the government and would like to negotiate further.

Sanchez has only been the country's leader in an acting capacity since April after failing to win a majority in the Spanish general election.

He first became prime minister of a minority government in June last year when parliament voted out a conservative government over a corruption scandal.

How many votes does Sanchez need to be named prime minister?

Sanchez had to receive the support of 176 members (an absolute majority) of parliament to be confirmed as prime minister on Tuesday.

However, as he didn't, MPs will vote again 48 hours after the initial vote and he'll need to be confirmed with a simple majority.

But if this fails again, King Felipe VI may have to stand in and propose new candidates. This, however, isn't likely, it's more accepted that the King will dissolve both chambers and will call new elections with the endorsement of the President of the Congress.

In which case, Spaniards could be heading back to the polls on November 10th.

Coalition with Podemos?

To avoid this from happening, the socialist leader has been negotiating to form a coalition government with the left-wing Podemos party after its leader Pablo Iglesias accepted to not seek a role in cabinet.

The first challenge is to sign a coalition agreement between Spain's Socialist Party (PSOE) and Podemos.

Both parties still need to agree on a government pact and who will be in the cabinet.

But even if they form a coalition, they will be short of a parliamentary majority, which means they will need the support of smaller parties, raising the question of how much the new government would be able to achieve.

With the 123 MPs and the 42 from Podemos and its partnered parties (En Común and En Comú Podem), Sanchez would also require the support or abstention of sovereignist parties such as Republican Left of Catalonia (ERC), who have 15 MPs and the Basque nationalist party Euskal Herria Bildu (4).

This way, the left would be able to overcome the right-wing bloc formed by the People's Party, Ciudadanos, and Vox, which counts with 147 votes. Not to add the two votes from the Canarian Coalition and another two from the Navarrese People's Union.

A coalition with Podemos would mean the left-wing bloc would get 165 votes, outperforming the 151 from the right-wing bloc.

What happens next?

It is unclear what Sanchez's next steps will be after the vote. Now that he's lost, Sanchez has until September 23 to decide whether to try again.

If he decides against another attempt, there will be a general election on November 10 — Spain's fourth in as many years.

Pablo Iglesias has urged Sanchez to keep negotiating with his party and not call an election.

Want more news?