STOCKHOLM (Reuters) - Sweden headed for a hung parliament after an election on Sunday that saw support for the nationalist Sweden Democrats surge, as one of Europe’s most liberal nations turned right amid fears over immigration.

Far-right parties have made spectacular gains throughout Europe in recent years as anxieties grow over national identity and the effects of globalisation and immigration following armed conflict in the Middle East and North Africa.

In Sweden, an influx of 163,000 asylum seekers in 2015 - the most in Europe in relation to the country’s population of 10 million - has polarised voters and fractured the long-standing political consensus.

With almost all districts having reported, the ruling centre-left Social Democrats and Greens and their Left Party parliamentary allies had 40.6 percent of the vote, while the opposition centre-right Alliance was at 40.3 percent.

That gave the centre-left 144 seats in the 349-seat parliament against 142 for the Alliance, suggesting weeks of uncertainty before a workable government can be formed.

The Sweden Democrats, a party with roots in the white supremacist fringe, won 17.6 percent and 63 seats, up from 12.9 percent and 49 seats in the last election four years ago, the biggest gain by any party in Sweden’s parliament, the Riksdag.

The results were largely in line with the conventional opinion polls tracked by Reuters in the run-up to the election but well below some online surveys that had predicted the Sweden Democrats could become the largest party.

While the results also fell short of leader Jimmie Akesson’s predictions of 20 percent of the vote or more, he told a party rally it was nevertheless the winner of the election.

“We will gain huge influence over what happens in Sweden during the coming weeks, months and years,” Akesson told party colleagues.

Akesson hopes his party, which wants Sweden to leave the European Union and freeze immigration, can play a decisive role in negotiations over forming a government.

He called on Ulf Kristersson, the centre-right Alliance’s candidate for the premiership, to choose between seeking support from the Sweden Democrats for an Alliance government or to accept another four years of Social Democrat Prime Minister Stefan Lofven.

Kristersson called on Lofven to resign, but 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.

Slideshow ( 16 images )

The Sweden Democrats, shunned by all the other parties since entering parliament in 2010, have promised to sink any Cabinet that refuses to give them a say in policy, particularly on immigration.

Lofven said he would not resign and called for cross-party cooperation to resolve the political impasse.

“There is no side with a majority. Then it is only natural to work across the political divide to make it possible to govern Sweden,” Lofven said.

Slideshow ( 16 images )

GROWING CHORUS OF EUROSCEPTICISM

The election will add to concerns in Brussels as the European Union enters campaign mode ahead of the European Parliament election in May, which could give more voice to eurosceptic groups and thwart efforts at closer EU integration.

The record levels of those seeking asylum in 2015 magnified worries about a welfare system in Sweden that many voters already believe is in crisis, even though refugee numbers have fallen sharply since then.

Lengthening queues for critical operations, shortages of doctors and teachers and the failures of police to deal with inner-city gang violence have shaken faith in the “Swedish model”, built on a promise of comprehensive welfare and social inclusion.

Akesson had labelled the vote a choice between immigration and welfare in a campaign that was unusually antagonistic.

Voting in central Stockholm, student Katze Collmar, 32, said the campaign had been “really unpleasant”.

“It feels like Sweden could take a step in this election that we won’t be able to recover from very easily.”

Lofven could hold on to power unless the Alliance accepts some kind of support from the Sweden Democrats, at a likely cost of the populists having more say over immigration policy.

But he would need to overcome decades of acrimony between the two blocs and get support from parties on the centre-right, something they have ruled out.

GRAPHIC - Swedish general election opinion polls: tmsnrt.rs/2LmSZFD

GRAPHIC - Sweden economy overview: tmsnrt.rs/2LmSZFD