Finland's Social Democratic Party declared a narrow victory in Sunday's general election after the party scraped a lead of just 0.2% over the far-right Finns Party with 99% of votes counted.

"For the first time since 1999, the Social Democratic Party is the party of the prime minister," leader Antti Rinne told supporters, after his party picked up 40 seats in parliament, one more than the Finns Party.

The close result will make negotiations to form the next coalition government particularly fraught.

With the European Parliament election less than two months away, the Finnish ballot is being watched in Brussels.

A strong result for the Finns Party could bolster a nationalist bloc threatening to shake up EU policy-making.

Underscoring the growing confidence among far-right politicians in Europe, anti-immigration parties have announced plans to join forces following the 26 May EU election, in a move that could give them major say in how the continent is run.

Just as the Social Democrats are benefiting from a growing sense of insecurity among Finland's older and poorer voters, the Finns argue that the nation has gone too far in addressing issues such as climate change and migration at its own expense.

"We are going through a cultural shock in Finland. Part of the population is in a kind of state of shock amid all the change going on, and as a result they take the Finns Party's hand," said Karina Jutila, chief researcher at think tank e2.

The success of Finland's Social Democrats marks a departure not only for Finland but also elsewhere in the region, where leftist parties have struggled in recent years, yielding some of their hold on the working class vote as anti-immigration nationalists of various stripes emerge.

In neighbouring Sweden, Prime Minister Stefan Lofven has precariously clung to power after his Social Democrats suffered their worst parliamentary election result in more than a century last autumn.

To do so, he had to enlist the support of two liberal parties with a pledge to enact a string of far-reaching right-wing policies.

In Denmark, which holds an election in June, the Social Democrats are gaining ground, in part after espousing the populists' anti-immigrant rhetoric.

Mr Rinne calls his party's immigration stance "the middle way", favouring work-related immigration to compensate for Finland's ageing population, but he also favours allowing some refugees in on humanitarian grounds, as the country has done thus far.

The 56-year-old former union leader is also promising to raise taxes to fund welfare and combat economic inequality, which he says has risen under the ruling centre-right coalition of prime minister Juha Sipila.

His talk of raising taxes is unlikely to drive off his supporters, many of whom value highly Finland's huge welfare state.

Altogether 19 parties ran in the election, with eight of them already holding seats in the parliament.