COPENHAGEN (Reuters) - Danish voters ousted Prime Minister Helle Thorning-Schmidt in an election on Thursday and handed power to an opposition centre-right alliance including huge gains for a eurosceptic, anti-immigrant party.
Opposition leader Lars Lokke Rasmussen said he would try to form a government but is likely to have to make big concessions to ensure support from the right-wing Danish Peoples' Party (DF), which ended up with more votes than his Liberal Party.
With all of the votes counted on the mainland, the centre-right won 90 seats in parliament to 85 seats for the centre-left bloc of Thorning-Schmidt, who wrongly gambled that an economic upturn would win her re-election.
Denmark's first female prime minister, elected in 2011, Thorning-Schmidt conceded defeat and quit as party leader after the vote.
DF, the second-biggest party behind Thorning-Schmidt's Social Democrats, has supported the Liberals in government before and its backing gives the centre-right led by Rasmussen its overall majority.
"Tonight we have been given an opportunity, but only an opportunity, to take leadership in Denmark," Rasmussen told supporters in parliament.
"We take that upon ourselves and I take that upon myself ... What I offer today is to put myself at the head of a government," he said.
DF's strong results were expected, but the party has been coy throughout the campaign about whether it would join a government for the first time in its 20-year history. It could leave the Liberals to form a government by themselves but support their policies in parliamentary votes, as it has done before.
"What we have said before the election is also what we will follow after the election - that we will be where the political influence is greatest," said DF leader Kristian Thulesen Dahl.
"If that is in a government, then that is where we will be. If it is outside of the government, then that is where we will be. That is the driver for us, not ministerial titles."
DF is acutely aware of the experience of other smaller parties in Denmark and elsewhere in Europe who, once in government, bled support due to compromises made with mainstream parties. Staying on the sidelines may paradoxically secure it more influence.
The party has already managed to set the agenda on some issues without being in government - mainstream parties across the political aisle talked about curbing immigration, following its lead, and DF won an important concession from centre-right parties on its stance on the European Union.
Just before the election, the centre-right parties agreed to support British Prime Minister David Cameron's bid to reform the EU. DF also wants to go further and call an in-or-out referendum on EU membership for Denmark.
Other politicians doubted DF would push for the prime minister's seat. When asked whether he saw Dahl as prime minister, Liberal Party vice chairman Kristian Jensen said: "I have a good imagination, but it has its limits".
Coalition building by the opposition bloc may last days or several weeks. Polls had projected a strong result for DF butpundits do not expect the party to form a government by itself.
While the Liberals and DF agree on most policy points, they disagree on public spending - Rasmussen wants to freeze it while Dahl wants to increase it in a country that is the largest state spender as a percentage of gross domestic product in the Organisation for Economic Cooperation and Development (OECD).
Opinion polls throughout the campaign put the centre-left and centre-right neck and neck. Thorning-Schmidt called an early election, hoping to capitalize on an economic recovery that followed unpopular reforms after she took power as Denmark's first female premier in 2011.
"We did not win the election and we were beaten at the finish line," Denmark's first female prime minister in power since 2011 told supporters. "Leadership is to step down at the right time. And that time is now."
Writing by Sabina Zawadzki and Alister Doyle; additional reporting by Alexander Tange, Annabella Pultz Nielsen and Erik Matzen; editing by Ralph Boulton and G Crosse