In what was a hugely entertaining encounter between the bottom two teams in Group E in Pretoria, Cameroon took the lead in the 10th minute through captain Samuel Eto'o following a bad defensive error by Christian Poulsen.
Denmark recovered from that setback though, and goals from Nicklas Bendtner and the dangerous Dennis Rommedahl in either half earned the Scandinavians a hard-fought victory.
The result means that Denmark joins its next opponent Japan on three points, while group leaders the Netherlands is now guaranteed a top-two finish - making it the first team to progress.
For battling Cameroon though, the defeat sees it become the first side to bid farewell to the World Cup after losing both its opening two games.
Denmark coach Morten Olsen made two changes to the side that lost to the Netherlands, bringing in fit-again captain Jon Dahl Tomasson and Jesper Gronkjaer.
Bendtner also took his place in the starting line-up for the second successive game despite struggling with a groin injury that means he can only train every other day and only having lasted an hour against the Dutch.
Cameroon coach Paul Le Guen, meanwhile, drafted in Geremi, Achille Emana and Alexandre Song as the Indomitable Lions sought to end an eight-game winless streak stretching back to the African Nations Cup.
Denmark, which had lost its previous three games without scoring a goal, had the first opportunity but Rommedahl fired over after breaking the offside trap in the sixth minute.
The Ajax winger should have done better with that, and four minutes later Eto'o showed him how it should be done by putting Cameroon ahead following a bad defensive error by Christian Poulsen.
Poulsen picked up possession from his goalkeeper Thomas Sorensen on the edge of the box and then attempted to find Simon Kjaer with a first-time pass without looking up.
The pass was intercepted by Emana, who quickly picked out the unmarked Eto'o in the middle and the Inter Milan star took one touch before drilling a low shot past Sorensen.
That was another bad goal for the Danes to concede following the own goal by Daniel Agger against the Netherlands, when Simon Poulsen's attempted headed clearance hit the Liverpool defender before going in.
The Danes were back on level terms just after the half-hour mark at Loftus Versfeld stadium, though.
Cameroon goalkeeper Souleymanou Hamidou had done well to deny Tomasson earlier but he could do nothing about the equaliser as his defence were cut open far too easily.
A superb long ball from inside his own half by Kjaer just cleared Benoit Assou-Ekotto and fell perfectly for the flying Rommedahl, and his low ball into the centre was slid home by Bendtner from eight yards.
Both sides had chances to snatch the lead during a hectic spell just prior to half-time.
For Denmark, Rommedahl could not take advantage of getting clear once again before, from the same attack, Tomasson saw a goal-bound shot blocked.
Then for Cameroon, Eto'o fired against the post following another defensive mistake, while Emana was denied by Sorensen after bursting through the two Danish centre-backs.
The all-action encounter continued apace at the start of the second half when Stephane M'bia and Kjaer both brought fingertip saves out of their opposing goalkeepers.
Cameroon striker Pierre Webo then blazed a decent opening high into the stands before also being denied by Sorensen as the African side looked to be taking control.
However, it was Denmark who got the next goal through the dangerous Rommedahl in the 61st minute.
Bendtner's pass put Rommedahl away down the right and the 31-year-old cut inside Jean Makoun before curling a low left-footed shot past Hamidou. That left Cameroon staring World Cup elimination in the face, and they almost fell 3-1 behind in the 71st minute, Hamidou coming to their rescue to superbly keep out Tomasson's effort.
Sorensen then produced an even better save six minutes later, diving low to his right to parry away Emana's shot.
Cameroon laid siege to Sorensen's goal in the closing stages, butit could find no way through as Denmark held on for the points.