Spain’s PM-elect has vowed to root out corruption and pledged to help people after years of public spending cuts under his predecessor.

Minutes after narrowly winning a no-confidence vote in parliament, Socialist party leader Pedro Sanchez signalled a change in tone and priorities.

Mariano Rajoy displayed an unbending commitment to reducing the national debt during his more than six years as prime minister.

Mr Sanchez, the 46-year-old head of what has been Spain’s main opposition party, has never held a government post.

He said he would address what he called the “social emergencies” of Spaniards after years of government austerity.

“I’m aware of the responsibility and the complex political moment of our country,” Mr Sanchez said after the 180-169 vote in the Congress of Deputies, Spain’s parliament. One representative abstained.

Mariano Rajoy
Mariano Rajoy was one of Europe’s longest-serving premiers (AP)

Mr Sanchez will be sworn in on Saturday at 11am local time (9am GMT) by King Felipe VI at the Zarzuela Palace in Madrid and will appoint his Cabinet over the coming days.

His triumph was a dramatic return to the spotlight after being fired as party leader less than two years ago.

Mr Sanchez said he intended to call elections before the end of this parliamentary term in 2020 but it’s likely he will want to make his mark with some headline policies before going to the polls.

A tough path lies ahead for his minority government. It will face a political minefield as it tries to steer legislation through parliament by winning support from rival parties. The Socialists only have 84 seats — just under a quarter of the total.

Pedro Sanchez
The result caps a remarkable comeback for the Socialist leader (AP)

Mr Sanchez said he would seek to build a consensus to try to weed out corruption.

He also said he wanted to “transform and modernise” Spain, including improving job security, fighting inequality, providing a better life for the elderly and investing in public health care.

The former economics professor and career politician inherits a strong economy in which growth last year reached 3.1%. But a question remains over where he might find the money to pay for his Socialist party’s ambitions.

Mariano Rajoy
The ousted prime minister Mariano Rajoy waves on leaving the parliament (AP)

Like the other 18 member countries of the eurozone, Spain is locked into rules that keep a lid on spending and hold debt at sustainable levels. After the eurozone’s recent financial crisis, any easing of those rules could spook markets.

Spain is the eurozone’s fourth-largest economy and an influential member of the European Union. Mr Sanchez and his party are staunch supporters of the EU and the shared currency.

Madrid’s stock exchange did not appear worried by Mr Sanchez’s rise to power and it closed nearly 1.8% up from the previous day.

Ana Pastor and King Felipe VI
Speaker of the Spanish Parliament Ana Pastor, right, told King Felipe VI of the new PM (Francisco Gomez/Pool Photo via AP)

The downfall of Mr Rajoy’s government came days after his Popular Party’s reputation was badly bruised by a court verdict that identified it as a beneficiary of a large kickbacks-for-contracts scheme.

That ruling spelled the end of Mr Rajoy’s rule and Mr Sanchez was keen to portray himself as a fresh start.

Mr Rajoy shook hands with Sanchez after the result was announced, leaving the chamber while lawmakers with the anti-establishment leftist party Podemos shouted: “Yes, we can.”

Spain Politics
Mariano Rajoy, right, shakes hands with socialist leader Pedro Sanchez (Pierre Phillipe Marcou/Pool Photo via AP)

Mr Sanchez has set himself apart from Mr Rajoy’s confrontational stance with separatists in Catalonia, Spain’s wealthiest region, where the Catalan government is making a noisy new push for independence.

He has promised to open talks with new Catalan President Quim Torra, despite having previously called the fervent secessionist’s comments “xenophobic”.