Spain's ruling socialist party won the most seats in the country's parliament Sunday but must seek support from smaller parties in order to stay in power.

With 99 percent of the ballots counted, the Spanish Socialist Workers' Party (PSOE) led by Prime Minister Pedro Sánchez had won 29 percent of the vote and captured 123 seats in the 350-member Congress of Deputies. At the other end of the political spectrum, the far-right Vox party was poised to enter the lower house of Parliament for the first time with about 10 percent of the vote, giving it 24 seats.

It was a bad night for the once-dominant Popular Party, which saw its representation cut to 66 seats from 135 following the last election in 2016. The onetime behemoth of Spanish conservativism lost votes to Vox as well as the center-right Citizens party, which will increase its number of seats to 57 from 32 three years ago.

THOUSANDS MARCH IN HONG KONG AGAINST EXTRADITION LAW

To remain in office, Sánchez will have to form a governing alliance with smaller parties, including the far-left United We Can, which lost 29 seats from the last election. Party leader Pablo Iglesias said late Sunday that he had already offered support to Sánchez, saying that he "would have liked a better result, but it's been enough to stop the right-wing and build a left-wing coalition government."

A coalition of Socialists and United We Can would hold a total of 165 seats, 10 short of the number need for a majority. That would leave Sánchez with a difficult decision about whether to make pacts with Catalan and other separatist parties — a move that would anger many Spaniards.

After having two main political parties for decades, Spain’s political landscape has fragmented into five parties. Voters have been disillusioned as the country struggled with a recession, austerity cuts, corruption scandals, the divisive Catalan independence demands and a rise in far-right Spanish nationalism.

The arrival of Vox in Madrid’s national parliament marks a big shift in 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.

"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, in reference to the 15th-century campaign by the Spanish Catholic Kings 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.

Turnout in Sunday’s vote was around 75 percent, up more than 8 points from 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.

CLICK HERE TO GET THE FOX NEWS APP

Pablo Casado, who had steered the Popular Party further to the right to stop it from losing votes to Vox, called the ballot the country’s “most decisive” in years.

"We have been losing our electoral support for several elections," he said.

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.

The Associated Press contributed to this report.