Victory comes just two years after he was forced out as leader of socialist party over refusal to back Rajoy government

Pedro Sánchez made history on Friday by becoming the first Spanish politician to unseat a prime minister through a motion of no-confidence.

That would be remarkable enough in itself, but the socialist leader’s victory over his old foe Mariano Rajoy is extraordinary for two other reasons.

Not only is the 46-year-old former economics professor no longer an MP, it is also less than two years since he was unceremoniously defenestrated as party leader over his refusal to facilitate Rajoy’s return to office following two inconclusive general elections.

Still reeling from a string of awful results and angered by Sánchez’s hardline position on the corruption scandals engulfing Rajoy’s People’s party, half of the PSOE’s executive committee launched a coup that prompted his resignation in October 2016.

Sánchez reacted to the rebellion by giving up his seat and announcing a road trip to reconnect with disgruntled socialists across Spain. “I won’t go against my party or against my electoral promises,” he said.

“On Monday I’ll get in my car and travel all round Spain to listen to those who haven’t been listened to, to the grassroots members and left-wing voters.”

His spell in motorway cafes and the political wilderness paid off. Seven months later, he stood again for the PSOE leadership and cruised to an easy victory over his main rival Susana Díaz, the president of the PSOE stronghold of Andalucía.

Sánchez, who was born in Madrid in 1972, joined the PSOE in 1993. After studying economic and business sciences at Madrid’s Complutense university, he picked up the first of three master’s degrees at the Free University of Brussels and worked in the European parliament.

In 1999, he served as chief of staff to the UN high representative to Bosnia during the Kosovo conflict. That was followed by stints as a self-employed consultant for foreign businesses, an economic adviser to the PSOE’s federal executive committee, and five years as a Madrid city councillor.

He was an MP between 2009 and 2011, when he lost his seat and headed back to academia. In 2013, he returned to parliament and was elected PSOE leader the following year. He is married with two daughters.

On Thursday night, Sánchez stood poised to replace Rajoy as prime minister. As luck would have it, the Spanish constitution smiles on the seatless: prospective PMs need only be Spanish and over the age of 18.

Less fortunately, his time in office is likely to be turbulent. His government will probably struggle to accommodate the myriad and very different demands of the parties that backed his motion as it prepares to hold the general election he has promised.

It will also have to deal with the issue of Catalan independence, a matter routinely described as the worst political crisis to hit Spain since it returned to democracy following the death of Franco four decades ago.

Sánchez is a passionate basketball fan and player, and unlike Rajoy he is also a keen linguist who says his time abroad helped him polish up on his English and French.

He will need a good turn of speed, as well as phrase, as he becomes only the second prime minister to negotiate Spain’s new political landscape.

The emergence of the anti-austerity Podemos and the centre-right Ciudadanos has threatened 40 years of PSOE and PP rule by capitalising on the anger of Spaniards over the economic crisis and the corruption of the political classes.

Add to that the secessionist threat from Catalonia and the PP’s anger over being thrown out of government after seven years, and Sánchez’s honeymoon looks likely to be a short one.