Madrid CNN  — 

Spanish Prime Minister Mariano Rajoy was toppled by a corruption scandal Friday, becoming the first leader in Spain’s modern democracy to lose a vote of no confidence in Parliament.

The demise of Rajoy – one of Europe’s longest-serving political leaders – paves the way for Pedro Sánchez, the leader of the main opposition Socialist party, to become Prime Minister.

Friday’s votein Madrid was the culmination of years of corruption allegations against Rajoy’s Popular Party (PP). The scandal came to a head last week when a court convicted his former aides of running slush funds to help finance PP election campaigns, prompting Sánchez to file the confidence motion.

The fall of Rajoy’s government comes at a time of wider political turmoil in Europe. Two populist parties in Italy have just reached an agreement to form a coalition government after months of wrangling, Brexit dominates UK politics and the European Union must now contend with a looming trade war with the US.

Spain’s political tumult is born of a long-running corruption scandal coupled with internal division. Although still feeling the effects of the global economic crisis, Spain’s economy is performing better than that of Italy, and anti-European sentiment played no part in its change of government.

Pedro Sanchez poses in the parliament after the motion of no confidence vote Friday.

Nonetheless, Sánchez, leader of the Spanish Socialist Workers’ Party (PSOE), faces significant challenges as he assumes office. Spain was riven last year by the Catalan independence crisis, which remains unresolved.

Rajoy’s fate was sealed on Thursday after the Socialists secured support for the no-confidence motion from a number of smaller parties in Parliament, including the Basque Nationalist Party.

In total, 180 of the chamber’s 350 lawmakers voted in support of the motion, a clear majority. There were 169 votes against and one abstention. It was the first time in Spain’s post-1977 democracy that a Spanish Prime Minister has fallen in this way.

Ana Pastor, President of the lower house of the Spanish Parliament, announced that Sánchez has “the trust of the Parliament” and so becomes the new Prime Minister of Spain. In line with the constitution, she was to inform Spain’s King Felipe II on Friday afternoon.

Sánchez received a standing ovation, with parliamentarians shouting: “Yes, it can be done.”

Outgoing Prime Minister Mariano Rajoy, left, shakes hands with Spain's new Prime Minister Pedro Sanchez after the vote.

Rajoy shook hands with Sánchez his 46-year-old successor, to congratulate him. Speaking shortly before the vote, Rajoy said he had been proud to serve his country. “It has been an honor to leave a better Spain than I found,” he said. “I wish my substitute could say the same when his day comes, for the good of Spain.”

Sánchez – a pro-European economics professor who was a keen basketball player in his youth – previously said that he would call for snap elections should he become Prime Minister.

He is expected to take office and nominate his Cabinet next week.

Posting on Twitter, Sánchez promised a fresh start for the country. “Spain starts a new page. A period to recover the dignity of its institutions. From responsibility, dialogue and consensus, it is time to work for equality, to build a country that does not leave anyone behind,” he said.

Separatist parties

Sánchez became PSOE leader in 2014, when the photogenic then-42-year-old was thought of as the new young and “handsome” face of politics.

But in 2016 his party performed poorly in elections and was unable to assemble a coalition government to keep Rajoy out of power. That didn’t sit well with some people in his party and in October of that year he resigned under pressure.

Pedro Sánchez addresses lawmakers Friday on the second day of debate on the no-confidence motion.

He then presented himself as a candidate for the primaries and won comfortably in 2017, proof that he remained popular with socialists in Spain. However, critics have accused him of wanting to become Prime Minister whatever the price.

Sánchez needed the support of fringe and pro-independence parties, as well as the anti-austerity Podemos party, to push the confidence motion through Parliament. And, since his own party holds only 84 seats, Sánchez will need to keep those parties, with their differing agendas, on his side in order to pass any legislation.

He has previously said he would stick to the budget recently passed by Rajoy’s government and continue to enact socioeconomic reforms.

Nathan Jones, a Spanish politics expert at Britain’s Nottingham Trent University, said the ousting of Rajoy’s government represented another step into the unknown for Spain.

“Thus far, few of the parties who backed the vote of no confidence in Rajoy have indicated that they will support Sánchez’s government, increasing the probability of a snap general election, the third since 2015, having to be called,” he said.

“Support for Sánchez from parties other than Podemos may yet still emerge; however, significant divisions remain between many of the political parties, thus establishing a stable government is far from certain.”

Rajoy: ‘A better Spain’

Rajoy,who came to office in 2011, had effectively conceded defeat ahead of the vote, congratulating Sánchez on his expected win in a brief address to Parliament.

“In light of what we all know, I presume that the vote of no confidence will go ahead, and Pedro Sánchez will become the Prime Minister and I want to be the first to congratulate him,” Rajoy said, visibly moved as he gave what was to be his last address as Spain’s leader.

“I will accept the result of the vote as the democrat I am, but I cannot agree with what has been done.”

Mariano Rajoy pauses during a speech ahead of the confidence vote on Friday at the Spanish parliament in Madrid.

Rajoy’s party has been plagued with corruption allegations for years. Rajoy himself has faced the humiliation of testifying in cases against PP members, though he has not been among the accused.

The confidence motion was filed by Sánchez after a court convicted Rajoy’s former aides of running slush funds to help finance Popular Party election campaigns. The court also questioned the credibility of Rajoy’s testimony during the proceedings.

It was the first time in Spain that a party had been convicted and fined on corruption-related charges.

Jean-Claude Juncker, president of the European Commission, tweeted his congratulations to Sánchez. “I trust that the Spanish government will continue contributing in a constructive way for a Europe that is stronger, more united and fairer,” he said, adding that Spain “plays a very important role” in the European project.

European Council President Donald Tusk also offered his congratulations, saying Sánchez’s appointment came at a “challenging time” for the continent. “European unity is now more needed than ever,” he said in a statement.

The Party of European Socialists (PES), made up of parties from across the European Union, welcomed Sánchez’s election, saying his government would form a “credible alternative to a conservative government hounded by corruption.”

PES President Sergei Stanishev described Sánchez as “a progressive and honest pro-European” who would “shift away from the austerity policies of the past years in his country.”

CNN’s Laura Perez Maestro reported from Madrid and Laura Smith-Spark wrote from London. CNN’s Vasco Cotovio contributed to this report.