His right-wing coalition of Liberals and Conservatives stormed to victory after a campaign dominated by asylum issues.
The far-right Danish People's Party also doubled its vote and won 22 seats - making it the third-largest party in the 179-seat parliament.
Mr Fogh Rasmussen, head of the winning coalition, is almost certain to succeed him in the post.
The election result ends almost a decade of Social Democrat-led government, and marks the first time since the 1920s that the Liberals have held more seats than the Social Democrats.
Mr Fogh Rasmussen declared it an historic day, and said he would try to unite Denmark.
"I want to form a broad co-operation. That would create the most durable results and security for the people," he said.
His chief policies, he said, would be to "reform hospitals, ensure better care of the elderly, increase maternity leave to one year... tighten policy regarding foreigners and, from day one, put a lid on taxes."
The People's Party leader, Pia Kjaeersgaard, has previously likened the inflow of refugees and immigrants to an invasion.
The election was called by Mr Nyrup Rasmussen in the aftermath of the 11 September attacks, as his popularity temporarily soared.
Correspondents say he assumed that voters would continue to rally behind his leadership in a time of international crisis.
But instead, the right-wingers campaigned vigourously for a tightening of immigration in the wake of the attacks, and voters backed them.
Mr Nyrup Rasmussen, who is not related to his rival, said his party would now be a fair and consistent opposition.
"The country we are now handing over to a centre-right government is a far better one than it was when we came to power almost nine years ago," he said.
Fears have been expressed by ethnic minorities and senior politicians that Ms Kjaeersgaard's party will be able to influence policy.
The Swedish Prime Minister, Goran Persson, was among those who voiced concern.
"It's clear I'm worried. We now see a centre-right government which will be forced to prop itself up with anti-foreigner ideas."
And policital analyst Ole Tonsgaard said: "Mr Fogh Rasmussen will have to listen to the (party)."
But Mr Fogh Rasmussen rejected concerns about the government's direction expressed by Liberals in other countries.
"They know us and it must be based on misunderstandings," he said.
Less than 5% of Denmark's 5.3 million population are foreigners - a lower figure than in many European nations.
Danes give more per capita than any other nation in the world to developing nations.