"So tonight I hand over the keys to the prime minister's office to Helle Thorning-Schmidt. And dear Helle, take good care of them. You're only borrowing them," Loekke Rasmussen said.

The result means the country of 5.5 million residents will get a new government that could roll back some of the austerity measures introduced by Loekke Rasmussen amid Europe's debt crisis.

A majority for the "red bloc" also deprives the anti-immigration Danish People's Party of the kingmaker role it has used to tighten Denmark's borders and stem the flow of asylum-seekers.

A power shift is not likely to yield major changes in consensus-oriented Denmark, where there is broad agreement on the need for a robust welfare system financed by high taxes.

Differing on austerity measures

But the two sides differ on the depth of austerity measures needed to keep Denmark's finances intact amid the uncertainty of the global economy.

Thorning-Schmidt said she would start government formation talks on Friday with the Social Liberals and the left-wing Socialist People's Party.

Loekke Rasmussen took credit for steering Denmark through the financial crisis in better shape than many other European countries.

However, the rebound has been slower than in neighbouring Nordic nations and the government projects budget deficits of 3.8 per cent of gross domestic product in 2011 and 4.6 per cent in 2012.

Although Denmark is not part of the debt-ridden eurozone, its currency is pegged to the euro and the country's export-driven economy is affected by shocks from Europe and beyond.

The economy emerged as the top election theme, to the chagrin of the Danish People's Party, which has used its kingmaker role in previous elections to push through immigration laws that are among Europe's toughest.

Thorning-Schmidt is not likely to make any major changes to those laws, but she has promised to overhaul a system of beefed-up customs controls at borders with Germany and Sweden, which critics say violates the spirit of European Union agreements on the free movement of people and goods.