MADRID (AP) — Opposition Socialist leader Pedro Sanchez has won a vote to replace Mariano Rajoy as prime minister, in the first ouster of a serving Spanish leader by parliament in four decades of democracy.

Sanchez won the no-confidence vote with 180 votes, a slim majority in the 350-seat lower house. There were 169 no votes and one lawmaker abstained.

Rajoy, one of Europe’s longest-serving heads of government, lost the vote following corruption convictions last week involving former members of his conservative Popular Party.

The 46 year-old Sanchez is now the prime minister in waiting. Spain’s King Felipe VI still has to swear him in.

Following the vote, Rajoy went over to Sanchez in the chamber and shook the incoming leader’s hand.