Denmark's centre-left has won the country's general election, ending nearly a decade in opposition.
With all votes counted, the bloc led by Social Democrat leader Helle Thorning-Schmidt had won a narrow majority in parliament.
She is set to become Denmark's first woman prime minister. Incumbent Lars Lokke Rasmussen has admitted defeat.
Ms Thorning-Schmidt had campaigned on a platform of tax rises and increased public spending.
She also promised to roll back tough immigration laws proposed by a junior partner of the current coalition.
The centre-left bloc won 89 seats in Denmark's 179-seat parliament against 86 for the centre-right. Turnout was high at 87.7%.
"We did it... today we've written history," Ms Thorning-Schmidt told jubilant supporters.
Mr Rasmussen said he had called Ms Thorning-Schmidt to congratulate her, but added: "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."
The "Blue Bloc" led by Mr Rasmussen has held power in Denmark for a decade.
The country has seen its worst economic downturn since World War II. Although Denmark is a member of the EU, it has chosen not to adopt the euro.
Mr Rasmussen's liberal-conservative alliance has long relied on the anti-immigrant People's Party (DPP) to push legislation through parliament.
The recent decision of Denmark, a Schengen state, to reimpose border controls came after pressure from the DPP, the third-biggest party in parliament.
However, the main issue of the election has been the health of the national finances.
Ms Thorning-Schmidt campaigned on a platform of tax rises and increased public spending, the BBC's Thomas Buch-Andersen in Copenhagen reports.
Although Mr Rasmussen was considered to have done well to steer Denmark through the financial crisis, its economic rebound is seen as sluggish and disappointing, our correspondent adds.
The economic crisis has turned Denmark's healthy surpluses into deficits, estimated to climb to 4.6% of GDP next year.
Local banks have also been struggling, with nine taken over by the state since the start of the crisis in 2008.
Ms Thorning-Schmidt has accused Mr Rasmussen of failing to spur growth and allowing the deficit to grow.
She advocates increased government spending, along with an unusual plan to make everyone work 12 minutes more per day, Reuters news agency reports.
An extra hour of productivity each week, the Social Democrats argue, would help kick-start growth.
"Denmark needs change, Denmark needs to move on and Denmark needs my leadership," Ms Thorning-Schmidt said.
The Social Democrat leader is a former MEP (member of the European Parliament) and is married to Stephen Kinnock, son of British Labour Party politicians Neil and Glenys Kinnock