MADRID — Two days after elections weakened his hand, Pedro Sánchez, Spain’s caretaker Socialist prime minister, made an abrupt U-turn on Tuesday and agreed to partner with a hard-left party he had previously rejected to form a government.
The preliminary deal between the Socialists and the smaller party, Unidas Podemos, came after five months of fruitless talks between them. Their partnership requires the support of several smaller parties in Parliament and still would leave Spain with a minority coalition government.
But the step was a breakthrough for a country where national parties, left and right, have been reluctant to compromise and come together, and it had the potential to break Spain’s long political deadlock.
It would also make Spain a standout in Europe, as one of the few countries with a left-wing government.
Mr. Sánchez’s reversal was clearly intended to salvage his political position after he made the misstep of forcing Spain’s fourth election in four years in hopes of strengthening his mandate.
That did not happen. Instead, the elections elevated the far-right Vox party as Spain’s third-most powerful political force. Mr. Sánchez’s Socialists lost three seats, ending with 120 in the 350-seat Parliament. And Podemos ended up with 35, down from 42 since Spain’s last elections in April.
The results provided a sobering warning to Spain’s squabbling parties on the left that their position was not improving, and it gave them new motivation to overlook their differences and reconcile.
In contrast to the acrimony displayed during their talks earlier this year, Mr. Sánchez and the leader of Podemos, Pablo Iglesias, smiled and hugged for the cameras on Tuesday.
Mr. Sánchez, 47, said the deal opened the door for “a progressive government” that he forecast would last for a full mandate of four years, despite its fragile minority situation. He thanked Mr. Iglesias for his generosity and said that he was “aware of the disappointment” that the breakdown of their previous talks had provoked.
Mr. Iglesias said that Sunday’s election had converted what in April could have been “a historical opportunity” into “a historical necessity” to form a left-wing coalition.
The deal is a personal victory for Mr. Iglesias, a 41-year old former university politics professor. Four years ago, Spain’s two-party system turned into a much more fragmented landscape, in part because of the emergence of Mr. Iglesias and his party.
Podemos, which modeled itself on the fleeting success of the hard-left Syriza party in Greece, once seemed like a rising insurgent threat to Spain’s political establishment. But Spain’s accelerating political fragmentation caught up with Podemos, too.
Until Tuesday’s announcement, Mr. Iglesias’ own leadership appeared to be under threat. One of the co-founders of Podemos broke ranks earlier this year to lead his own party, but to little success in Sunday’s election.
Podemos has called for a sweeping fiscal overhaul that would raise taxes on corporations and the rich, while increasing Spain’s minimum wage. It has promoted a 34-hour workweek and caps for property rental prices.
The party also wants banks to reimburse the government for the bailout money they received during Spain’s 2012 financial crisis while keeping Bankia, the main rescued bank, under state control.
Mr. Iglesias has argued that another independence referendum in Catalonia — with terms set by Madrid — could help end Spain’s territorial conflict.
Catalonia could be one of several sticking points between Mr. Sánchez and Mr. Iglesias if they end up working together, with Mr. Iglesias serving as deputy prime minister, as they agreed Tuesday.
It also remains to be seen whether the two leaders have overcome their personal animosity. In July, Mr. Iglesias agreed to keep himself out of a coalition in order to overcome Mr. Sánchez’s personal veto. That offer proved insufficient at the time to break the deadlock and avoid another election.
After Sunday’s election, Mr. Sánchez found himself under intense criticism for his miscalculated election strategy and for risking another lengthy period of deadlock. In 2016, Spain also held a repeat election, but then spent 10 months without an elected government.
The pressures on Mr. Sánchez have only mounted with the latest flare-up of the secessionist conflict in Catalonia. After former Catalan separatist leaders were sentenced to prison last month, mass protests spilled over into violence on the streets of Barcelona and other Catalan cities. Right-wing politicians accused Mr. Sánchez of failing to guarantee law and order in Spain’s restive northeastern region.
Santiago Abascal, the leader of the far-right Vox party, which doubled its representation in Parliament to 52 seats, denounced the left-wing government deal.
Mr. Iglesias and his party, he stressed, had supported “Bolivarian Communism” and several far-left politicians in Latin America.
He also accused Mr. Iglesias of supporting separatist politicians in what he described as an attempted coup in Catalonia.
“We will hold them responsible for every damage that they provoke to cohabitation and the constitutional order,” Mr. Abascal warned on Twitter.
To continue in office, Mr. Sánchez will now hope to get the support of several smaller parties, including Basque and Catalan ones. That is the same unwieldy alliance that allowed Mr. Sánchez in 2018 to unexpectedly win a vote of no confidence against the conservative prime minister, Mariano Rajoy, and replace him.
The leader of the Basque Nationalist Party, Andoni Ortuzar, indicated on Tuesday that his party would back Mr. Sánchez, as it did last year.
Pablo Casado, the conservative leader who took over from Mr. Rajoy last year, said on Tuesday that his Popular Party would vote against a left-wing coalition government, alongside Vox.
Mr. Casado told a news conference that it was “very worrying” that Spain’s government could include “radicals” like Mr. Iglesias and other members of his party.
Mr. Sánchez and Mr. Iglesias made public on Tuesday a list of government priorities in which Catalonia placed second-to-last among 10 items, even though tensions over Catalonia’s future dominated much of the election campaign.
In the text, the two leaders said they would work to promote dialogue in Catalonia, without giving details.
To get enough support in Parliament, Mr. Sánchez will most likely have to rely on at least some of the Catalan separatist parties abstaining from the vote.
During the final days of the election campaign, Mr. Sánchez hardened his stance toward the Catalan government significantly, which may now complicate his task.
On Tuesday, the spokeswoman for the current Catalan government, Meritxell Budó, said that Mr. Sánchez should assume responsibility for forcing a repeat election.
That decision has created “more instability and more far-right,” given Vox’s rise, she said.