Sweden's ruling centre-right coalition beat the Social Democrat opposition in yesterday's election but failed to win an outright majority and the far-right Sweden Democrats won seats in parliament for the first time.

Early results showed Prime Minister Fredrik Reinfeldt's four-party Alliance coalition winning 173 seats in the 349-seat parliament, just three short of a majority. The result makes Reinfeldt, the Moderate party leader, the first non-socialist to win re-election since the late 1970s. The Social Democrat-led opposition bloc won 156 seats while the anti-immigration Sweden Democrats got 20 seats, entering parliament for the first time.

Last night Reinfeldt declared victory and said he would remain in power and try to build a coalition with the Green party.

"We have said that the biggest bloc should rule, and that is the Alliance," he told party workers at an election night party in central Stockholm.

Sweden's Social Democrat-led opposition leader conceded defeat and said it was up to Reinfeldt to build a majority government.

"The Alliance is in all probability the largest minority," Mona Sahlin told party supporters. "They are in the driver's seat when it comes to building a government. We lost."

Reinfeldt's bid to hold on to power, built on small budget deficits, tax cuts and strong economic growth, is being closely watched by David Cameron. Both leaders have rebranded their parties and entered into partnerships with centrist liberals.

However, Reinfeldt's majority was undermined by the far right, who have sought to harness anti-immigrant sentiment in a country where one in seven residents is foreign-born.

The strong performance by the Sweden Democrats and the prospect of a hung parliament looked likely to trigger a fall in the krona against the euro and volatility on the Stockholm financial markets.

The governing coalition and the centre-left opposition bloc have pledged not to join forces with the Sweden Democrats.

The rise of the far-right party, which has moved away from its skinhead roots under a youthful leadership and the slogan "Tradition and Security", reflects a wider anti-immigrant backlash across Europe, as recession and budget cuts take hold. In their campaign, the Sweden Democrats raised the spectre of creeping Islamicisation of society and promised to crack down on immigration.

It would not be the first time that an anti-immigrant grouping has entered Sweden's parliament. A short-lived rightwing protest won nearly 7% of the vote in 1991.

Reinfeldt's coalition ended the long Social Democratic hegemony four years ago on a pledge to lower taxes and to trim the country's generous welfare benefits. The economy is expected to grow by 4% this year and the budget deficit is on track to becoming the smallest in the EU.

An unaccustomed second consecutive defeat is likely to lead to a shake-up of the Social Democrats.

Under Sahlin, who was vying to become the country's first female prime minister, the party warned during the campaign that Sweden's long tradition of fairness and compassion was under threat from the government budget cuts.

• This article was amended on 22 September 2010. The original said that Prime minister Fredrik Reinfeldt becomes first non-socialist to win re-election since the 1930s. This has been corrected.