For Denmark, a nation of 5.5 million people, the election turned on the issue that has also divided many other Western nations struggling with low growth, large government deficits and historic levels of national debt: what mix of government spending and tax policies to adopt in order to restore economic health and avoid slipping further toward a crisis like Greece’s.

Image Helle Thorning-Schmidt is likely to lead Denmark. Credit... Krabbe Lars/POLFOTO, via Associated Press

The Social Democrats’ campaign was based on Ms. Thorning-Schmidt’s promises to raise taxes on Denmark’s banks and its wealthiest citizens to pay for better schools and hospitals, and to finance a $4 billion expansion of what is already one of Europe’s most generous welfare systems. Her most headline-catching nod to austerity came with her proposal to add 12 minutes to the average Dane’s working day, and she also acknowledged the need to take action on the deficit, which is set to rise to 4.6 percent of gross domestic product in 2012, well above the European average.

The departing center-right bloc, led by Mr. Loekke Rasmussen, pointed to Europe’s deepening financial crisis and said Denmark should keep tight control of its public finances, avoiding “uncontrolled debt,” and not adopt tax increases that would stifle its weak economic recovery, with a projected growth rate this year of 1.25 percent. Denmark is Scandinavia’s worst-performing economy, with a growth rate less than half of Norway’s and less than one-third of Sweden’s.

Ms. Thorning-Schmidt built an early lead in the polls, which narrowed sharply in the last days of the campaign, and on election night her coalition appeared to have a sliver of a parliamentary majority. At midnight in Copenhagen, the election count indicated that the red bloc had 89 seats in the 179-seat Parliament and was likely to secure another 3, with Mr. Loekke Rasmussen’s blue bloc winning 86 seats and likely to win one more.

One feature of the decade-long rule of the center-right parties that seemed unlikely to change significantly was the tight new restraints on immigration, which have most heavily affected Denmark’s population of about 200,000 Muslims, many of them asylum seekers. With Muslims now accounting for nearly 4 percent of the population, according to the United States State Department, and Islam now the largest non-Christian denomination in the country, opinion polls have shown strong support for the controls, which Ms. Thorning-Schmidt said any government she led would maintain.