The vote was very close. The Guardian reports:
Mariano Rajoy, once viewed as the great survivor of Spanish politics, has been ousted as prime minister in a vote of no confidence after several former members of his party were convicted of corruption in a case that proved a scandal too far. He will be replaced by Pedro Sánchez, the leader of Spain’s opposition socialist PSOE party, which tabled the motion to unseat him.
Sánchez’s motion won the support of 180 MPs – four more than the 176 needed in the 350-seat parliament. There was one abstention and 169 MPs opposed it. Sánchez vowed to address the “social urgencies” of Spaniards after years of austerity under Rajoy’s conservative government, adding that he was “aware of the responsibility and the complex political moment of our country”. After the vote, Rajoy went over to Sánchez in the chamber and shook the incoming leader’s hand.