Denmark looks set to be led by a eurosceptic coalition after Helle Thorning-Schmidt's coalition government was defeated by the centre-right opposition.
Speaking after resigning in the early hours of 19 June, Denmark's first female prime minister told Social Democratic party members: "Every single day the responsibility has been mine. I stand by the decisions I have made ... I was Denmark's first female prime minister, but I won't be the last."
Thorning-Schmidt is married to British Labour MP Stephen Kinnock, the son of former party leader Neil Kinnock.
With all votes counted, preliminary official results showed the opposition bloc led by the liberal Venstre party of former prime minister Lars Løkke Rasmussen had won the 90 seats needed to secure a majority in the 179-seat parliament.
"Four years ago we handed over the keys to the prime minister's office. I then said it was only a loan," he told supporters in Copenhagen. "There is a majority that believes that Denmark needs a new government and gives us a possibility to get the keys back."
Thorning-Schmidt said: "We were beaten on the finish line. I know that Lars Løkke loves Denmark and he should be happy that he takes over a Denmark that is in great shape."
However, Venstre, which lost support, too, will need the help of the eurosceptic Danish People's party (DPP), which nearly doubled its vote to 21%, up from 12% just four years ago.
"What this suggests is that the Danish People's party is becoming a real people's party, for which we have fought for so many years," its leader, Kristian Thulesen Dahl, told supporters.
However, he did not immediately say whether he would join a coalition or support Venstre from outside government.
"The most important for the Danish People's Party is to get political influence," Thulesen Dahl said.
Boost for David Cameron in the EU
Rasmussen's apparent victory is likely to help David Cameron's cause in the EU, because the Venstre leader has said he would push for reforms against deeper integration.
He and his likely coalition partners have all announced their joint support for Cameron's bid to renegotiate the terms of Britain's EU membership, in particular with regard to welfare benefits for migrants from within the 28-member bloc.
"We will stand behind Great Britain and like-minded nations' efforts to ensure that the EU doesn't turn into a social union," said the statement, titled Danish Welfare in Europe. "We want an EU where people can go wherever workers are needed, but we don't want an EU where people go wherever the social benefits are good."