Despite taking the lead through skipper and three-time African Footballer of the Year Samuel Eto'o with a coolly taken goal after only 10 minutes, Cameroon failed to capitalise on any of the dozen or so clear-cut and half-chances they also created.
At the death they could find no response to Nicklas Bendtner's 33rd minute equaliser and Dennis Rommedahl's well-taken 61st minute curler that secured the victory.
Some solid saves by Danish goalkeeper Thomas Sorensen, some bad luck, and excellent Danish defending after a woeful early error, all contrived to send Cameroon to an unlikely defeat.
Their distraught players slumped to the ground in disbelief when Uruguayan referee Jorge Larrionda brought an excellent match which had seen 36 attempts on goal -- 23 from Cameroon -- to an end.
The result at the Loftus Versfeld Stadium meant that the Netherlands, who beat Japan 1-0 in Durban earlier, were through to the last 16, while either Denmark or Japan, who both have three points, will join them.
Cameroon will wonder what might have been as their elimination hardly looked likely for the first half-an-hour.
SELF CONFIDENCE
Resplendent in their green, red and yellow kit and kicking off with new-found self-confidence after French coach Paul Le Guen responded to the players demands to restore his more experienced players like Alexandre Song and Geremi into the starting lineup, they fully deserved their early lead.
They were given an enormous hand in the goal by Christian Poulsen's careless clearance straight to Pierre Webo. Webo found Eto'o and he kept his composure to rifle the ball past Sorensen from 10 metres out.
Denmark, though with their veteran captain Jon Dahl Tomasson running the midfield engine room, prompted his team's openings with balls wide to Rommedahl whose probing crosses, while initially cleared, would lead to the equaliser.
The genesis of the goal came in a 70-metre crossfield ball from Simon Kjaer, whose pass to Rommedahl, way off in the distance on the opposite flank must rank as the pass of the tournament so far.
The 31-year-old veteran winger took on the defender and his low cross found Bendtner who timed his run perfectly to slide home.
There was little let up in the excitement after that goal either, with Denmark going close to a second, two minutes before Eto'o hit the post at the other end after a jinking run.
Webo then had a superb chance to put Cameroon back in front after an hour when he made time and space for himself but as he twisted to shoot, he seemed to run out of gas and his shot was a weak one.
Denmark cleared that threat and within seconds the ball was nestling in the back of Cameroon's net.
Rommedahl cut inside Jean Makoun, on as a substitute, who allowed the winger too much space and time to cut inside and the winger sent a curling shot wide of goalkeeper Hamidou Souleymanou for what proved to be the winner.
Cameroon though, maintained their shape, their resolve and their heads and with Achille Emana and Eto'o at the heart of most of their raids, increasingly forced the Danes on to the back foot.
Makoun, who allowed Rommedahl space to score, almost made amends late in the game but his chance, and Cameroon's place in the tournament, agonizingly slipped away.