MADRID — Spain’s Socialist Party strengthened its hold on the government on Sunday in the country’s third national election since 2015, with nearly complete results showing growing political polarization and party fragmentation.

The elections came after an abrupt change of government in June, when Pedro Sánchez and his Socialist Party used a corruption scandal to oust Prime Minister Mariano Rajoy’s conservative Popular Party in a parliamentary vote.

Late Sunday, Mr. Sánchez, the current prime minister, declared victory again, even though his party fell short of an absolute majority in Parliament and he will need to find coalition partners to form a government. The Socialists won 123 of the 350 seats in Parliament, with 99.9 percent of the votes counted.

An anti-immigration and ultranationalist party, Vox, won its first seats in Parliament, a major shift in a country that long appeared to be immune to the spread of far-right movements across Europe, in part because of the legacy of the Francisco Franco dictatorship. But its 10 percent share of the vote left it in no position to play kingmaker and help form a governing coalition.