Samuel Eto'o and Geremi Njitap scored as DR Congo lost to Cameroon - but the Simbas still edged out Angola for a place in the quarter-finals.
Eto'o scored his fifth goal of the tournament
In the other Group B match Angola could not score enough goals against 10-man Togo to move ahead of the DR Congo on goal difference.
Both teams finished with four points - but Claude Le Roy's team qualified as they had drawn with Angola and had a marginally better goal difference.
Although the final Group B games were supposed to start and finish at the same time the Angola-Togo match concluded eight minutes before the other match.
And the final few minutes of the game between Cameroon and DR Congo saw the Congolese happily allow their opponents to keep the ball in their own half.
Earlier in the match the Indomitable Lions had shown that even with several reserves on the pitch they were head and shoulders above their group rivals.
The match was also notable for a blatant red card - this time Gladys Bokese was dismissed for kicking Achille Webo.
The Congolese created the first chance - it fell to the impressive Zola Matumona but his shot straight at Carlos Idriss Kameni was easily saved.
Alioum Saidou had Cameroon's first serious effort on goal, but Congo's Pascal Kalemba was able to make a smart save.
However, Kalemba's fortunes quickly changed when Salomon Olembe teed-up Geremi from a free kick for the Chelsea striker to smash the ball home.
It was a nervous 90 minutes for DR Congo coach Le Roy
Two minutes later Cameroon scored again after Geremi played Eto'o through while the DR Congo defence waited for an offside flag.
Eto'o's scuffed his shot, but it bounced off the post, onto Kalemba's head and back over the line.
Albert Ze Meyong then headed wide, Geremi shot straight at Kalemba and Olembe miscued from the edge of the area as Cameroon ran the Congolese ragged.
Le Roy made two personnel changes at half time, bringing on Mutamba Milambo and Tshatsho Kabamba for Marcel Mbayo and Lelo, and one tactical, pushing Kabamba up as a second forward alongside LuaLua.
But it made little difference, as Eto'o curled a sumptuous free kick on to the bar, and then sent in a shot that Kalemba only just kept out.
The Congolese keeper might even have been sent off when he brought down the on-rushing Cameroon substitute Webo, but the referee Koman Coulibaly showed a lenient yellow card.
Coulibaly had no choice but to dismiss Bokese after he kicked out at Webo after the two players had tangled.
But 10-man DR Congo did not concede again to seal a quarter-final tie against Egypt, while group winners Cameroon face the Ivory Coast.
Cameroon coach Artur Jorge:
"It is true that we did not finish the match well.
"However if children have spent 80 minutes at full speed it is understandable they get tired.
"We were perhaps a bit fortunate with the two goals but we were determined to win this match."
DR Congo coach Claude Le Roy:
"I take my hat off to Cameroon. I am not proud of tonight. We have qualified through the back door.
"I am ashamed of what Bokese did. There is no room for that in football."