It was the night the political establishment struck back.
Against all expectations, the centre-left Socialist party also managed to hold off a determined challenge from the far-left Podemos movement. Polls predicting political upheaval were proven utterly wrong.
With the Brexit shock still reverberating around Europe, Spanish voters plumped for the familiar safety of the nation’s much-maligned establishment parties.
Not known for his natural exuberance, Mr Rajoy appeared visibly delighted as he greeted supporters outside party headquarters in the early hours of Monday morning. He even kissed his wife.
The crowd repeatedly broke into chants of “Si, se puede!” (Yes we can), mockingly appropriating the habitual battle cry of Podemos leaders and supporters.
“We won the election, and we claim the right to govern,” Mr Rajoy declared.
In fact, forming a new government under his leadership will be anything but easy. The PP won 137 seats in Spain’s 350-seat parliament. To be elected prime minister, Mr Rajoy will therefore need the backing — in one form or another — of both the Socialists and the centrist Ciudadanos party.
Without the Socialists, a combination of the PP, Ciudadanos and two smaller parties from the Basque country and the Canary Islands would secure 175 votes — just one short of an absolute majority.
Mr Rajoy’s path to power is anything but straightforward. But with the PP gaining 14 seats and all other parties either in stagnation or decline, building an alternative majority will be harder still. On Monday, most opposition leaders were officially sticking to their anything-but-Rajoy line. But behind those statements, there was a growing sense of inevitability.
“Rajoy has reinforced his position and it will be harder to make a case against him,” said Manuel de la Rocha, economic adviser to the Socialist party leader Pedro Sánchez. “We think now is the time for him to take the lead and try and form a government. But the Socialists will not support him. He must try to find other allies.”
Ciudadanos leader Albert Rivera, meanwhile, rushed to declare on Monday that there “was never a veto” against Mr Rajoy. The statement was clearly at odds with his party’s previous insistence that it would refuse to back another Rajoy-led government, and suggested that Ciudadanos was preparing for a retreat into the arms of the PP.
Mr Rivera’s leverage, in any case, is minimal. His party lost a fifth of its seats in parliament on Sunday night and probably has more to fear than any other group from another early election.
“There is no alternative leftwing coalition available and no one wants a third election,” said Pablo Simón, a professor of politics at the Carlos III University in Madrid. His conclusion: “Mariano Rajoy has gained legitimacy and he will now try to hang until the end in an attempt to lead the next government.”
For the Socialists, Sunday’s vote carried a certain bittersweet note. On the one hand, they managed to defend their traditional role as the standard bearer of the Spanish left, despite poll after poll showing they were on course to fall behind Unidos Podemos, the joint electoral list formed by Podemos and the far-left Izquierda Unida party. On the other, the Socialists’ chances of winning back power after five years of PP rule are minimal; there is simply no viable coalition available to them.
In his speech on Sunday night, Mr Sánchez made no attempt to conceal his anger at Podemos. Back in March, his attempt to unseat Mr Rajoy and usher in a coalition government made up of the Socialists and Ciudadanos was voted down by Podemos. “I hope [Podemos leader] Pablo Iglesias reflects on the fact that he could have put an end to the government of Mariano Rajoy — and that he did not want to.”
For Mr Iglesias and other Unidos Podemos leaders, the results came as a shock. The polls had given them every reason to look forward to the much-vaunted sorpasso (the eclipse of the Socialists). Now they face the daunting challenge of holding together an unwieldy alliance of different parties and interest groups divided both by geography and ideology.
Many of those differences — for example over coalition strategy and the issue of Catalan independence — were set aside during the campaign. Mr Iglesias will now have to confront and resolve them head-on.
At a time when the political mainstream is under siege across Europe, Sunday night brought a rare sight in Madrid: for once, the long faces belonged to the insurgents, and the smiles to the establishment.
Copyright The Financial Times Limited 2016. You may share using our article tools.
Please don’t cut articles from FT.com and redistribute by email or post to the web.