A penalty from Chelsea star Deco four minutes from time looked to have secured a routine win for the Portuguese, coached by former Manchester United assistant manager Carlos Queiroz, after Arsenal's Nicklas Bendtner had levelled the hosts' opener on 42 minutes from United winger Nani.
However, in a frantic finale, the Danes turned the match on its head as Christian Poulsen netted in the 90th minute and Daniel Jensen scored the clincher in the second minute of time added on.
The win gives Morten Olsen's side a massive boost after they could only draw their first match away to Hungary, while the Portuguese, still badly missing the injured Cristiano Ronaldo, won 4-0 at little Malta.
It was the first time in 12 years that Portugal had lost a FIFA World Cup qualifying match, the last defeat coming in October 1996 in Ukraine.
Queiroz, who replaced Luiz Felipe Scolari after UEFA EURO 2008, added: "This is the result of two critical moments in which we didn't score and that gave confidence to Denmark. They believed all the way until the end. We tried to hold the game after the 2-1, now we need to recover these three points in the away game," he said.
With only the top side guaranteed to go through and Sweden also in the Group 1 mix, Queiroz will have to rally the troops after this unexpected home loss.