Updated

Voters in Sweden handed the ruling Social Democrats their worst result in decades Sunday, while the far-right Sweden Democrats were projected to become the third-largest party in Stockholm's parliament.

With almost all the ballots counted, the Social Democrats had emerged as the largest party but had just 28.3 percent of the vote, making it likely to lose a significant number of seats.

The Moderates party was next at 19.8 percent, followed by the Sweden Democrats at 17.6 percent. That's a 4.6 percent increase in their vote share from the last election, held in 2014.

Sunday's results make it unlikely that any party will have a majority of the 175 seats in the Riksdagen, Sweden's parliament. It could take weeks or months of coalition talks before the next government is formed.

Lofven Sweden

Swedish Prime Minister Stefan Lofven has been in office since 2014. (COPYRIGHT TT NYHETSBYRÃ…N)

Both the left-leaning bloc led by the Social Democrats and the center-right bloc have said they would refuse to consider the Sweden Democrats as a potential coalition partner.

Sunday's election was the first since the Swedish government in 2015 allowed 163,000 migrants into the Scandinavian country with a population of 10 million. The number was far lower than the asylum-seekers Germany accepted that year, but the highest per capita of any European nation.

The Sweden Democrats — led by Jimmie Akesson — worked to soften its neo-Nazi image while helping to break down longstanding taboos on what Swedes could say openly about immigration and integration without being shunned as racists.

The potential of a surge by the party had many Swedes worried about an erosion of the humanitarian values that have long been a foundation of their country's identity.

AkessonSD 720

Sweden Democrats leader Jimmie Akesson. (Stina Stjernkvist/TT via AP)

"This election is a referendum about our welfare," Prime Minister Stefan Lofven said. "It's also about decency, about a decent democracy ... and not letting the Sweden Democrats, an extremist party, a racist party, get any influence in the government."

At the party's rally on Saturday, Akesson strongly criticized Lofven's government for "prioritizing" the cause of immigrants over the needs of citizens.

"This government we have had now ... they have prioritised, during these four years, asylum-seekers," Akesson said, giving an exhaustive list of things he says the government has failed to do for Swedish society because of migrants.

The Associated Press contributed to this report.