STOCKHOLM (Reuters) - Sweden faces a political impasse after its mainstream center-left and center-right blocs virtually tied in an election on Sunday, while the far-right - which neither wants to deal with - made gains on a hardline anti-immigration platform.

With nearly all votes counted on Monday, the ruling center-left Social Democrats and Greens and their Left Party parliamentary ally had 40.6 percent of the vote, while the opposition center-right Alliance was on 40.3 percent.

That translates into a single-seat advantage in the 349-member Riksdag.

The Sweden Democrats, a party with white supremacist roots, won 17.6 percent, about 5 percentage points more than four years ago. It was the biggest gain of any party and in line with conventional opinion polls but fell short of the 20-30 percent their leader Jimmie Akesson had predicted.

The Sweden Democrats’ success follows a rise in popularity of other far-right parties in Europe amid growing anxiety over national identity, the effects of globalization and fears over immigration boosted by conflicts in the Middle East and Africa.

(For a graphic on Sweden's election result click, tmsnrt.rs/2CDMT4e)

Akesson was adamant his party holds the balance of power. “We won’t participate in letting through a government which doesn’t give us influence,” he told TV4. “On the contrary, we will do what we can to bring down any such government.”

Akesson’s overtures found few takers with a letter inviting the right-wing Moderates and Christian Democrats to talks being instantly and publicly rebuffed.

Unless parties on the center-left and center-right break ranks with their blocs, it is likely to be impossible to form a stable government without some kind of support from the Sweden Democrats, who want the country to leave the European Union and freeze immigration.

Slideshow ( 6 images )

Liberal Party leader Jan Bjorklund said he wanted to form a center-right minority government and seek cooperation with the Social Democrats or the Greens.

He said the complicated situation meant he could not completely rule out supporting a Social Democrat-led government but said he would rather leave the Alliance than work with the Sweden Democrats.

“Should any party in the Alliance start cooperating with the Sweden Democrats then the Alliance will fall, but it will not happen,” he said in an interview for Swedish Television.

Many online surveys, which in the last election had gauged the Sweden Democrats’ vote better than conventional polls, had signaled they could dethrone the Social Democrats as the nation’s biggest party - a position the center-left has held for a century.

In the end, the Sweden Democrats were beaten by Prime Minister Stefan Lofven’s Social Democrats by a 10 percentage point margin and eclipsed also by the Moderates of Ulf Kristersson, the Alliance’s candidate for the premiership.

“In some sense we’re happy the Sweden Democrats didn’t grow more than they did,” Liberal Party lawmaker Allan Widman told Reuters. “The bigger they become, the more hard pressed all other parties become.”

GRAPHIC - Election result tmsnrt.rs/2CDMT4e

Slideshow ( 6 images )

SENSE OF RELIEF

Sweden saw itself as a “humanitarian superpower” for years, but a rise in gang violence in immigrant-dominated, deprived city suburbs has also won support for the Sweden Democrats.

After the arrival of 163,000 asylum seekers in 2015 - the most in Europe in relation to the country’s population of 10 million - the government suspended many of its liberal asylum policies.

There was a sense of relief among supporters of mainstream parties about the far-right’s less dramatic gains. That was shared in Brussels. “It is clear that the claim that the far-right is on an inexorable roll and will devour everything that stands in its way is false,” said one EU official.

Still, the Swedish election underscored a broader shift to the right in one of Europe’s most socially progressive nations.

Senior figures in the mainstream parties headed into meetings on Monday to produce a strategy for forming a government. But the process could take weeks and possibly fail.

OVERSEAS VOTE

Akesson challenged Kristersson to choose between seeking support from the Sweden Democrats for an Alliance government or accepting four more years of Lofven as prime minister.

Kristersson called on Lofven to resign, but also rebuffed Akesson. “We have been completely clear during the whole election. The Alliance will not govern or discuss how to form a government with the Sweden Democrats,” he said.

Both sides laid claim to being best placed to form a government, although votes from Swedes living abroad are not due to be declared until Wednesday and these could still sway the final outcome slightly.

Yet in the same breath, leaders of both sides called for bipartisan accommodation to avoid gridlock in parliament.

The scenario of a bipartisan coalition is highly uncertain.

Center-left and center-right parties have ruled together only a handful of times since the mid-1930s. Also, a 2014 accord to neutralize the Sweden Democrats and let the biggest bloc rule proved deeply unpopular among center-right grassroot members and rapidly unraveled.

The Moderates - the biggest party in the Alliance - are not interested in cooperating with the Social Democrats and any such deal would also raise questions about democratic accountability. Voters might see the Sweden Democrats as the country’s only opposition party.

A new election will be called if parliament doesn’t agree on a prime minister after four attempts.