Denmark’s Social Democrats are in pole position to form a new government after winning Wednesday's election, with results suggesting the party’s tougher stance on immigration attracted voters back from the far right.

With all votes counted, official results show the Social Democrats secured 26 percent of the vote, which would earn them 48 of the 179 seats in parliament. This put them ahead of the Liberal Party of current Prime Minister Lars Løkke Rasmussen on 23 percent of the vote, or 43 seats.

Parties supporting Social Democrat leader Mette Frederiksen to be the next prime minister together secured 91 seats, versus 75 seats for the right of center “blue bloc” supporting Rasmussen, paving the way for Frederiksen to get the first shot at forming a government.

The remaining seats went to unaligned parties.

Frederiksen claimed victory in a speech to supporters in Copenhagen.

“Thank you to the Danish voters, you have voted for a new direction for Denmark and a new government,” she said.

Wednesday’s victory followed a change in the Social Democrats' strategy under Frederiksen, who took over as leader shortly after an election defeat for the party in 2015.

Frederiksen maintained her party’s commitment to high taxation and public spending, but she repositioned the Social Democrats much further to the right on the issue of immigration.

As the main opposition party under Rasmussen, the Social Democrats backed a range of much tougher border controls proposed by the Liberal Party government and its ally, the far-right Danish People’s Party, including the confiscation of valuables from asylum seekers, intended to offset costs to the state for their time in Denmark.

The Social Democrats believed the new strategy could help them reconnect with disaffected former supporters who had shifted to the Danish People’s Party.

As she cast her vote in the town of Værløse, just outside Copenhagen, earlier on Wednesday, Frederiksen said she thought the party’s change of tack had been effective.

“Danes are responding positively to the Social Democrats,” she said. “Voters who have deserted us over recent years, who thought our immigration policy was wrong, have come back this time, that is what many have told me,” she told reporters.

Still, the Social Democrats' hard line on immigration appears to have cost the party support from some voters who objected to the new position, but the results also suggested those voters may have moved to the Social Democrats’ allies on the left: Support for the left-leaning Socialist People’s Party and the Social Liberal Party rose in Wednesday’s election.

Meanwhile, support for the Danish People's Party more than halved to around 9 percent from around 20 percent in 2015.

“This hurts, we must look at what we did wrong and what we can learn,” Danish People’s Party leader Kristian Thulesen Dahl said as the results came in.

The Social Democrats will now try to form a single-party minority government with the support of the Social Liberal Party, the Red-Green Alliance and the Socialist People’s Party.

Negotiations over the formation of a new government could take time as these parties are some distance apart on a range of key issues, including immigration and fiscal policy.

The Danish election was also closely watched for what it might mean for Margrethe Vestager, the Danish European competition commissioner, who is a member of the Social Liberal Party and is gunning for the position of Commission president after Jean-Claude Juncker.

To continue to compete for the top job, Vestager must secure the backing of the new government in Copenhagen. The Social Democrat victory leaves this an open question, as the party has so far refused to offer an opinion on who should be Denmark's choice for a Commission position.

“We should let the electorate decide who should form a government at the election on Wednesday and after that, we will decide on the issue of the Danish commissioner,” senior Social Democrat lawmaker Nicolai Wammen said earlier this week.

The Social Democrats might back Vestager as Denmark's Commission nominee in an effort to secure the support of her Social Liberal Party for its government platform, analysts have said.

But on stage in Copenhagen, Social Democrat leader Frederiksen’s focus was on national politics.

“I am proud of the positive campaign we have run," she said. "Now it is over and it is a time to find solutions. Now we have a chance to set a new direction for Denmark."