Denmark has elected its first female prime minister, ousting the right-wing government from power after 10 years of pro-market reforms and ever-stricter controls on immigration.
Near complete official results showed a left-leaning bloc led by Social Democrat Helle Thorning-Schmidt would gain a narrow majority in the 179-seat Parliament.
"There is no parliamentary support for our government," outgoing Prime Minister Lars Loekke Rasmussen said, adding he would present his Cabinet's resignation to Queen Margrethe, Denmark's figurehead monarch.
"So... 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 Denmark 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.
The opposition won 89 of the mainland seats compared to 86 for the governing coalition, according to preliminary results with 99% of votes counted. The "red bloc" was expected to win at least two of the four seats allocated to the semi-autonomous territories of Greenland and the Faeroe Islands.
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. 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, 44, wants to protect the welfare system by raising taxes on the rich and extending the average working day by 12 minutes.
Loekke Rasmussen says tax hikes would harm the competitiveness of a nation that already has the highest tax pressure in the world. "We need sound public finances without raising taxes," Loekke Rasmussen, 47, told reporters after casting his ballot in Graested, north of Copenhagen.