MPs in the Spanish Congress voted in a confidence vote to oust Mariano Rajoy (Popular Party, PP) from his post and appoint Socialist Party (PSOE) leader Pedro Sánchez—who is not an MP—as the new Prime Minister.

Mr. Sánchez earned the 176 votes necessary for an overall majority at 11:32 a.m.

The final result was 180 in favour, 169 against and one abstention.

A week ago, Pedro Sánchez and the PSOE were languishing at around or less than 20% of the vote in the polls, with commentators wondering if the Socialist Party was still relevant.

Now, suddenly, he is the new Prime Minister of Spain.

The Socialist Party (PSOE) returns to power after José Luis Rodriguez Zapatero was ousted by Mariano Rajoy and the PP at the general election in 2011.

The Spanish Constitution stipulates that the successful candidate becomes PM immediately.

The Spanish Congress confirmed to The Spain Report on Friday morning that the Speaker would notify the result of the vote to the King straight away.

Podemos, the Basque Nationalist Party (PNV) and the two Catalan separatist parties in parliament—Esquerra (ERC) and PDeCat—voted in support of the motion.

Ciudadanos and the PP voted against.

"It is an honour to have been Prime Minister", said Mr. Rajoy in his final remarks to the chamber: "Pedro Sánchez will be the new Prime Minister and I want to be the first to congratulate him".

He said he was pleased to leave Spain "better than I found her".

The outgoing leader turned up late to parliament. On Thursday evening, he spent eight hours in a restaurant in central Madrid with a group of ministers instead of attending the rest of the debate in Congress.

OK Diario reported two bottles of whisky had been drunk by the party and posted video footage of Mr. Rajoy hugging the chef before he left the establishment, guided by his bodyguards to the official car.

The Deputy Prime Minister, Soraya Sáenz de Santamaría, placed her handbag on the PM's seat in the chamber, providing a useful rhetorical device for opposition parties in their remarks.

This motion of no confidence, tabled by the PSOE last Friday, is the first time in the modern democratic period that such a challenge has succeeded, and the first time the government of the country has changed hands so quickly.

In editorials, Spain's leading newspapers slammed the political manoeuvre.

El País said the new socialist government would be "artificial and not viable". El Mundo wrote that the events of the last week "are already another page in our surrealist history".

Subscribe Now To Understand Spain Better, In English

Original, independent reporting and insight take you deeper into a changing country.

Spain is a fascinating country, its history full of intriguing characters and events, and the story is not over yet.

Catalan independence, Podemos, corruption, economic recovery and now a political crisis that might bring Rajoy's government down.

The truth still needs to be told, power still needs holding to account. Our collective futures depend on our ability to understand how our societies are evolving.

The Spain Report gives you fast reporting and deeply informed analysis of the latest news, events and trends changing this wonderful country, in English.

Your subscription guarantees our news and analysis are 100% independent.

Subscribe Now