STOCKHOLM — Sweden looked set for a period of political confusion after election results on Sunday put a center-right bloc and the governing center-left coalition neck and neck, while a far-right, anti-immigration party came in third — winning a higher percentage of the vote than ever before, but achieving less of a breakthrough than polls had suggested.
With more than 99 percent of ballots counted, the national election commission reported that the governing center-left Social Democrats had 28.4 percent of the vote, making it the largest single vote-getter, but handing the party its worst showing in decades.
The center-right Moderate party was next at 19.8 percent, while the far-right Sweden Democrats were running third, with 17.6 percent, up from 12.9 percent in 2014 but a less successful showing than many Swedes had feared. Some polls had predicted that the Sweden Democrats would come in second, with more than 20 percent of the vote.
The red-green bloc of center-left, leftist and environmental parties, led by the Social Democrats, had 40.6 percent of the vote. The center-right alliance, led by the Moderates, was just behind with 40.3 percent. The results mean neither bloc can command a majority in Parliament, and both have rejected the idea of any deal with the Sweden Democrats.
The campaign was unusually polarizing in a country known for seeking political consensus. The main issues were also the most contentious: immigration, crime, the welfare state and, after a summer of forest fires, the environment.
For some voters, the fierce debates were a welcome change.
“In Sweden we have been too afraid to discuss the issues,” said Anders Nilsson, 54, an I.T. engineer who voted for the Center party in Botkyrka, a diverse suburb south of Stockholm. “Now we dare to discuss tough questions.”
This election has been one of the most closely watched in Sweden’s recent history, with a focus on how the Sweden Democrats would perform given the rise of anti-immigration populist parties in countries like Germany, Italy and Austria.
“The world’s eyes are on Sweden and the path it takes,” Annie Loof, the head of the Center Party, said in a debate before the vote.
The Social Democrat prime minister, Stefan Lofven, who runs a minority government of the center-left, had warned voters on Saturday not to cast their ballots for what he called a “racist” party.
“This election is a referendum about our welfare,” he 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.”
Jimmie Akesson, the leader of the Sweden Democrats, told supporters on Saturday that the current government had “prioritized, during these four years, asylum-seekers,” listing failures to do more for health care, housing and pensioners. “Sweden needs breathing space,” he said. “We need tight, responsible immigration policies.”
The results on Sunday followed another recent European election pattern: the shrinking of mainstream parties of the center-left and the center-right as they lose votes to more extreme parties on both sides of the political spectrum, as well as to environmentalist parties.
In Sweden, this shift has raised questions about whether the main parties will keep their vows to have no dealings with the Sweden Democrats, or whether they will have to reach some understanding with the party, especially on crucial budget votes.
The main parties may try to negotiate some sort of grand coalition, but that would be unusual in Sweden, where minority governments are fairly common.
“This is a new situation for Sweden,” said Soren Holmberg, a political scientist who heads the SOM Institute, an independent research group at the University of Gothenburg. “What is pretty clear is that there won’t be a majority on either side, so it means we have to have a lot of negotiation between the blocs.”
About 7.5 million registered voters chose from almost 6,300 candidates for a four-year term in the 349-seat Parliament.
Arian Vassili, a 23-year-old engineering student who voted Sunday in Botkyrka, said he supported the Social Democrats. “This is an incredibly important election,” he said. “This is an election about values, how you view people, your fellow human beings and whether we are going to take care of each other.”
Maria Enberg, 42, a cook who lives in Botkyrka, said she had voted for the Center party. “The Sweden Democrats have become so big, and I really wanted to vote against them. I don’t want any racist party governing in Sweden.”
The Sweden Democrats’ rise began in 2010, when the party crossed the 4 percent threshold for Parliament seats, getting 5.7 percent of the vote. In 2014, its vote share rose to 12.9 percent, making it Sweden’s third-largest party.
The Sweden Democrats have greatly benefited since the migration wave of 2015, when 163,000 asylum seekers came to Sweden, about 1.6 percent of the population.
Under Mr. Akesson’s leadership, the party has tried to soften its image. It now uses for the party logo a floppy flower in Sweden’s colors of blue and yellow instead of a flaming torch, and the party insists that it will not tolerate racism. But it campaigned on keeping “Sweden Swedish,” cracking down on crime and questioning whether immigrants and Islam will alter the country’s identity.
As in Germany, stricter border controls have been introduced in Sweden, and the numbers of new immigrants has fallen steeply, to about 23,000 this year.
But the political damage had been done, and despite a thriving economy and generally low unemployment, the Sweden Democrats argued that immigration should stop and that resources should go to refurbishing Sweden’s famous welfare state, which is strained by an aging population and the challenge of taking on migrants.
During the campaign, the right-wing party spoke directly about traditionally taboo subjects like identity, Islam, integration and crime, winning supporters who felt the traditional parties had been reluctant to touch such sensitive issues. The party, along with the Left party on the other extreme, has benefited from a general sense of discontent and loss of confidence in the political system.
Li Bennich-Björkman, a political scientist at Uppsala University, said it was “sort of shocking” that the Sweden Democrats could come this far, but she noted that the party, which has disavowed its roots in the white supremacist movement, had transformed.
“I would say that the major part of their electorate are not racist and fascist,” Ms. Bennich-Björkman said. “They have managed very skillfully to transform themselves into a variant of the Social Democratic party, just with more nationalist ambitions,” she said.
The Social Democrats, who have dominated the country for a century, built Sweden’s welfare state. But their support has declined from 45 percent in 1994 to just over 28 percent on Sunday. The Left Party had 7.9 percent of the vote, and the Green Party 4.4 percent.
The Moderate party, led by Ulf Kristersson, leads the center-right bloc. He was chosen in October 2017 to head the party when his predecessor, Anna Kinberg Batra, resigned after suggesting that it might be possible to work with the Sweden Democrats. In its alliance, the Center Party won 8.6 percent of the vote, the Christian Democrats 6.4 percent and the Liberals 5.5 percent.
On Sunday night, Mr. Kristersson called on the prime minister to resign. “This government has run its course,” he told a party rally.
With the two blocs so close to each other, negotiations over forming a government are expected to be drawn out. “Usually we are quick in forming a new government,” said Mr. Holmberg, the political scientist. “This time it could drag on for weeks or months.”
Both centrist parties have moved to the right under the pressure of the Sweden Democrats and have promised tougher policies on immigration, the integration of refugees and crime.
Daniel Suhonen, the head of Katalys, a trade union research group, said he saw “very sad” parallels in the United States for the Sweden Democrats’ rise.
“They had a clear answer, like Trump,” he said at a Social Democrats event. “They said all the problems in Sweden are created by an elite that is corrupt and ruined the country with immigration, and you can see that in your bad pension, the lack of affordable housing for your adult children. They said you can solve it if you stop immigration.”
Christina Anderson reported from Stockholm and Steven Erlanger from Brussels.