|PM Helle Thorning-Schmidt and former PM Lars Lokke Rasmussen|
The right-wing, anti-immigration Danish People's Party will become the second-largest in parliament.
The DPP is now expected to join Mr Rasmussen's ruling coalition.
The DPP's leader Kristian Thulesen Dahl had previously (in Danish) poured cold water on the idea of going into government.
He told Denmark's Politiken he preferred "the little free bird role, which can make the Danish People's Party come closer to getting our policy through in the real world than you think".
But Mr Dahl could yet be in a position to make a bid to become prime minister.
By midnight local time (22:00 GMT) 99% of votes had been counted. Results from four seats in Greenland and the Faroe Islands have yet to be included.
Ms Thorning-Schmidt's governing Social Democratic Party was the biggest party, winning at least 26.3% of the vote, according to Danish broadcaster DR.
But her allies failed to gain as much of the vote as those of the opposition.
According to DR, the DPP won 21.1% of the vote, and Mr Rasmussen's Denmark Liberal Party came third on 19.5%.
Welfare and immigration exercised Danish voters more than the economy.
Anger at perceived benefit tourism led the traditionally pro-immigration Social Democratic Party to launch an advertising campaign with the slogan: "If you come to Denmark you should work."
Mr Rasmussen, who led the country between 2009 and 2011, suggested that benefits are so high that there is barely any incentive for Danes or immigrants to work.
Way back in 2009, Telegraph reporter Adrian Michaels warned that Europe was in trouble because they were ignoring the mass immigration, particularly of Muslims. It took Denmark another 6 years to recognize that problem; 6 more years of the problem multiplying. But, at last, the people have responded, and are now far ahead of their EU neighbours who have buried their stupid heads in the sand.
The report, which follows, makes for fascinating reading, especially when you consider that his stats are quite dated, and that so little has changed, so few governments are willing to address the problem.
By Adrian Michaels 08 Aug 2009
Britain and the rest of the European Union are ignoring a demographic time bomb: a recent rush into the EU by migrants, including millions of Muslims, will change the continent beyond recognition over the next two decades, and almost no policy-makers are talking about it.
The numbers are startling. Only 3.2 per cent of Spain's population was foreign-born in 1998. In 2007 it was 13.4 per cent. Europe's Muslim population has more than doubled in the past 30 years and will have doubled again by 2015. In Brussels, the top seven baby boys' names recently were Mohamed, Adam, Rayan, Ayoub, Mehdi, Amine and Hamza.
Europe's low white birth rate, coupled with faster multiplying migrants, will change fundamentally what we take to mean by European culture and society. The altered population mix has far-reaching implications for education, housing, welfare, labour, the arts and everything in between. It could have a critical impact on foreign policy: a study was submitted to the US Air Force on how America's relationship with Europe might evolve. Yet EU officials admit that these issues are not receiving the attention they deserve.
Jerome Vignon, the director for employment and social affairs at the European Commission, said that the focus of those running the EU had been on asylum seekers and the control of migration rather than the integration of those already in the bloc. "It has certainly been underestimated - there is a general rhetoric that social integration of migrants should be given as much importance as monitoring the inflow of migrants." But, he said, the rhetoric had rarely led to policy.
The countries of the EU have long histories of welcoming migrants, but in recent years two significant trends have emerged. Migrants have come increasingly from outside developed economies, and they have come in accelerating numbers.
The growing Muslim population is of particular interest. This is not because Muslims are the only immigrants coming into the EU in large numbers; there are plenty of entrants from all points of the compass. But Muslims represent a particular set of issues beyond the fact that atrocities have been committed in the West in the name of Islam.
America's Pew Forum on Religion & Public Life, part of the non-partisan Pew Research Center, said in a report: "These [EU] countries possess deep historical, cultural, religious and linguistic traditions. Injecting hundreds of thousands, and in some cases millions, of people who look, speak and act differently into these settings often makes for a difficult social fit."
How dramatic are the population changes? Everyone is aware that certain neighbourhoods of certain cities in Europe are becoming more Muslim, and that the change is gathering pace. But raw details are hard to come by as the data is sensitive: many countries in the EU do not collect population statistics by religion.
EU numbers on general immigration tell a story on their own. In the latter years of the 20th century, the 27 countries of the EU attracted half a million more people a year than left. "Since 2002, however," the latest EU report says, "net migration into the EU has roughly tripled to between 1.6 million and two million people per year."
The increased pace has made a nonsense of previous forecasts. In 2004 the EU thought its population would decline by 16 million by 2050. Now it thinks it will increase by 10 million by 2060. Britain is expected to become the most populous EU country by 2060, with 77 million inhabitants. Right now it has 20 million fewer people than Germany. Italy's population was expected to fall precipitously; now it is predicted to stay flat.
The study for the US Air Force by Leon Perkowski in 2006 found that there were at least 15 million Muslims in the EU, and possibly as many as 23 million. They are not uniformly distributed, of course. According to the US's Migration Policy Institute, residents of Muslim faith will account for more than 20 per cent of the EU population by 2050 but already do so in a number of cities. Whites will be in a minority in Birmingham by 2026, says Christopher Caldwell, an American journalist, and even sooner in Leicester. Another forecast holds that Muslims could outnumber non-Muslims in France and perhaps in all of western Europe by mid-century. Austria was 90 per cent Catholic in the 20th century but Islam could be the majority religion among Austrians aged under 15 by 2050, says Mr Caldwell.
Projected growth rates are a disputed area. Birth rates can be difficult to predict and migrant numbers can ebb and flow. But Karoly Lorant, a Hungarian economist who wrote a paper for the European Parliament, calculates that Muslims already make up 25 per cent of the population in Marseilles and Rotterdam, 20 per cent in Malmo, 15 per cent in Brussels and Birmingham and 10 per cent in London, Paris and Copenhagen.
Recent polls have tended to show that the feared radicalisation of Europe's Muslims has not occurred. That gives hope that the newcomers will integrate successfully. Nonetheless, second and third generations of Muslims show signs of being harder to integrate than their parents. Policy Exchange, a British study group, found that more than 70 per cent of Muslims over 55 felt that they had as much in common with non-Muslims as Muslims. But this fell to 62 per cent of 16-24 year-olds.
The population changes are stirring unease on the ground. Europeans often tell pollsters that they have had enough immigration, but politicians largely avoid debate.
France banned the wearing of the hijab veil in schools and stopped the wearing of large crosses and the yarmulke too, so making it harder to argue that the law was aimed solely at Muslims. Britain has strengthened its laws on religious hatred. But these are generally isolated pieces of legislation.
Into the void has stepped a resurgent group of extreme-Right political parties, among them the British National Party, which gained two seats at recent elections to the European Parliament. Geert Wilders, the Dutch politician who speaks against Islam and was banned this year from entering Britain, has led opinion polls in Holland.
The Pew Forum identified the mainstream silence in 2005: "The fact that [extreme parties] have risen to prominence at all speaks poorly about the state and quality of the immigration debate. [Scholars] have argued that European elites have yet to fully grapple with the broader issues of race and identity surrounding Muslims and other groups for fear of being seen as politically incorrect."
The starting point should be greater discussion of integration. Does it matter at all? Yes, claims Mr Vignon at the European Commission. Without it, polarisation and ghettoes can result. "It's bad because it creates antagonism. It antagonises poor people against other poor people: people with low educational attainment feel threatened," he says.
The EU says employment rates for non-EU nationals are lower than for nationals, which holds back economic advancement and integration. One important reason for this is a lack of language skills.
The Migration Policy Institute says that, in 2007, 28 per cent of children born in England and Wales had at least one foreign-born parent. That rose to 54 per cent in London. Overall in 2008, 14.4 per cent of children in primary schools had a language other than English as their first language.
Muslims, who are a hugely diverse group, have so far shown little inclination to organise politically on lines of race or religion. But that does not mean their voices are being ignored. Germany started to reform its voting laws 10 years ago, granting certain franchise rights to the large Turkish population.
It would be odd if that did not alter the country's stance on Turkey's application to join the EU. Mr Perkowski's study says: "Faced with rapidly growing, disenfranchised and increasingly politically empowered Muslim populations within the borders of some of its oldest and strongest allies, the US could be faced with ever stronger challenges to its Middle East foreign policies."
Demography will force politicians to confront these issues sooner rather than later. Recently, some have started to nudge the debate along. Angel Gurría, the OECD secretary-general, said in June: "Migration is not a tap that can be turned on and off at will. We need fair and effective migration and integration policies; policies that work and adjust to both good economic times and bad ones."