With 99% of ballots counted, the Socialists led by Prime Minister Pedro Sánchez won 29% of the vote, capturing 123 seats in the 350-seat Congress of Deputies. The new far-right Vox party made its national breakthrough by capturing 10% of the vote, which would give it 24 seats.
Sánchez announced that he would soon open talks with other political parties, telling crowds gathered at the gates of his party headquarters in central Madrid that "the future has won and the past has lost."
He hinted at a preference for a left-wing governing alliance but also sent a warning to Catalan separatists whose support he may need that any post-electoral pact must respect the country's 1978 constitution, which bans regions from seceding.
"The only condition is to respect the constitution, move toward social justice, coexistence and political cleanliness," Sánchez said of his criteria for working with other parties. Vox's success came at the expense of the once-dominant conservative Popular Party, which fell to 66 seats, losing more than half of its representation since the last election in 2016. The conservatives lost votes both to Vox and to the center-right Citizens party, which will increase its number of seats from 32 to 57.
Voters in Spain had become disillusioned as the country struggled with a recession, austerity cuts, corruption scandals, divisive demands for independence from the restive Catalonia region and a rise in far-right nationalism not seen since Spain's dictatorship ended in the 1970s.
"We told you that we were going to begin a reconquering of Spain and that's what we have done," Vox leader Santiago Abascal said, referring to the 15th century campaign by Spanish Catholic kingdoms to end Muslim rule in the Iberian Peninsula.
Vox, which was formed five years ago, has promised to defend Spain from its "enemies," citing feminists, liberal elites and Muslims among others. Its emergence on the national stage gives Spain five political parties, furthering political fragmentation in a country that was alternately ruled for decades by the Socialists and the Popular Party.
To stay in office, the Socialists and Sánchez must form a governing alliance with smaller parties, including the far-left United We Can led by Pablo Iglesias. Iglesias said after the vote the he "would have liked a better result, but it's been enough to stop the right-wing and build a left-wing coalition government," adding that he's already offered support to Sánchez.
But Sánchez will still need support from 11 more seats to produce a 176-seat majority in the lower house of parliament, meaning he may be forced to make pacts with Catalan and other separatist parties — moves that would anger many Spaniards on the left and the right.
Pablo Casado, who had steered the Popular Party further to the right to try to stop it from losing votes to Vox, called his party's worst ballot result ever "very bad," saying that "we've been losing our electoral support for several elections."
The once-dominant conservative party also took a big blow in the Senate, losing the absolute majority to the Socialists. Turnout was nearly 76%, up more than 8 points since the previous election in 2016. The vote surge included a huge boost in the northeastern Catalonia region, which has been embroiled in a political quagmire since its failed secession bid in 2017 put separatist leaders in jail while they are tried.
The arrival of Vox in Madrid's national parliament marks a big shift for Spain, where the far right has not played a significant role since the country's transition to democracy following the death of dictator Gen. Francisco Franco in 1975.
The Popular Party and the Citizens party had focused their campaigns on unseating Sánchez, hinting they could create a conservative coalition government — with the backing of Vox — like a regional one that recently ousted the Socialists from southern Andalusia.
Political pundits have predicted a long road to forming a government, with parties likely to put the brakes on negotiations in order not to hurt their chances in elections to the European Parliament at the end of May, which in Spain coincide with regional and township ballots.
The political scenario will be further complicated because regionalist parties and separatists also surged as a response to fear of a possible crackdown from a Vox-influenced right-wing government, said Cristina Ares, a senior politics lecturer at the University of Santiago de Compostela.
"This means that there is a significant sentiment against centralization and in favor of regionalization," she said, pointing at that as one of the challenges that the new prime minister will face. Speaking Sunday after voting, Sánchez said he wanted a mandate to undertake key social and political reforms.
The prime minister said he wanted "a stable government that with calmness, serenity and resolution looks to the future and achieves the progress that our country needs in social justice, national harmony" and in fighting corruption.
At the Palacio Valdes school in Madrid, voter Alicia Sánchez, a 38-year-old administrator, worried about the influence of Vox. "I've always come to vote, but this time it feels special. I'm worried about how Vox can influence policies on women and other issues. They are clearly homophobic. Reading their program is like something from 50 years ago," she said.
Having voted in all elections since Spain returned to democratic rule four decades ago, Amelia Gómez, 86, and Antonio Román, 90, said they had little faith in any of the candidates. "All I want is for whoever wins to take care of the old people," Gómez said, complaining that together the two of them receive less than 1,000 euros ($1,100) a month in state pensions.
Associated Press writer Aritz Parra reported this story in Madrid and AP writer Joseph Wilson reported from Barcelona.
This story has been corrected to show that a pact between the Socialists and the United We Can party would need 11 more seats, not 15, to reach a 176-seat majority in the lower house of parliament.