Social Democrats win 40 seats in the 200-seat parliament, two more than the right-wing Finns Party.

Finland’s leftist Social Democrats party has won the general election by a thin margin, capturing two more seats than the nationalist Finns Party, according to final results from the justice ministry.

The results reflect a mounting sense of insecurity in the Nordic nation over immigration, welfare and climate change.

Tipped to win, the opposition Social Democrats scored 17.7 percent, winning 40 seats in the 200-seat parliament, while their eurosceptic Finns Party rivals were at 17.5 percent – 38 seats – after Sunday’s election.

The joint ruling Centre Party of Prime Minister Juha Sipila and centre-right National Coalition stood at 13.8 percent and 17 percent, respectively, marking the first time in a century that no party won more than 20 percent in a general election.

With a fragmented parliament and deep divisions within the mainstream parties over how to tackle rising costs of expensive public services, coalition talks following the election could be protracted.

But Social Democrat leader Antti Rinne, 56, a former union boss, was expected to have the first shot at forming a government, with most party leaders having ruled out cooperation with the populist Finns.

“For the first time since 1999, we are the largest party in Finland … SDP is the prime minister’s party,” Rinne told supporters and party members celebrating in central Helsinki.

A first-place spot would put the Social Democrats at the head of the government for the first time in 16 years.

The Finns Party, led by hardline member of the European Parliament Jussi Halla-aho, has seen a surge in support in recent months during an anti-immigration dominated campaign, urging people to “Vote for some borders”.

The party could hold significant influence in the talks to form the next government, which in Finland is typically a coalition of three or four parties.

Immigration became a hot election topic following outrage in January over highly publicised reports of an alleged string of sexual assaults by immigrant men. The incidents boosted support for the Finns Party’s anti-immigration agenda.