In an amazing finish in Bouake, Ebrima Colley scored on 85 minutes to put Gambia 2-1 up only for Joseph Gomez to concede an own goal before an added-time Christopher Wooh goal won a thriller.
Defending champions Senegal beat Guinea 2-0 in the other Group C match to finish with nine points and Cameroon edged Guinea for second place on goals scored after both collected four.
Guinea also qualified for the knockout stage as one of the best four third-placed teams while pointless Gambia head home.
Victory for five-time champions Cameroon meant four-time winners Ghana were eliminated after finishing third in Group B on Monday with only two points.
Apart from group winners and runners-up, the best four third-placed teams from the six sections qualify for the round of 16 and at least four of them will have more points than Ghana.
Hosts Ivory Coast, who suffered a stunning 4-0 defeat by Equatorial Guinea on Monday, will survive if Zambia and Tanzania lose their final Group F matches on Wednesday.
Karl Toko Ekambi was restored to the starting line-up by coach Rigobert Song after playing in a draw with Guinea and being an unused substitute in a loss to Senegal.
Although Cameroon are 80 places above Gambia in the world rankings, they came under considerable first-half pressure and were lucky to be level at 0-0 by half-time.
Goalkeeper Fabrice Ondoa, recalled in place of Manchester United shot-stopper Andre Onana, parried a hard close-range shot from Ali Sowe to safety in the early stages.
Fast tempo
He rescued Cameroon again after 35 minutes, grasping the ball after a Yankuba Minteh header after a corner appeared goal-bound.
Ondoa was in action again soon after, diving to push away a snap shot by Musa Barrow, who either scored or created the four Gambian goals at the 2022 AFCON, where they were quarter-finalists.
Although the opening half produced no goals there was plenty to entertain a 24,000 crowd with the tempo surprisingly fast given the temperature was 34 Celsius (94 Fahrenheit).
Winger Georges-Kevin Nkoudou was prominent early in the second half as Cameroon finally applied continuous pressure.
He had a genuine penalty appeal after a tackle from behind ignored by the Ethiopian referee, then rattled the woodwork with a close-range drive.
Cameroon were barely recognisable from the team that struggled in the opening half and they broke the deadlock on 56 minutes through Toko Ekambi.
The Saudi Pro League star soared between two Gambian defenders and stayed just onside to powerfully head a Nkoudou cross past goalkeeper Baboucarr Gaye.
Gambia refused to panic, however, pushed forward and levelled on 72 minutes when Ablie Jallow stroked a cross wide of Ondoa and into the net.
The match was being fought at a frenetic pace and Toko Ekambi burst into the area and watched in despair as his shot rebounded off the crossbar.
Then came the sensational climax with three goals in six minutes before Cameroon set up a last-16 showdown with Nigeria on Saturday.
(AFP)
Newer articles
<p> </p> <div data-testid="westminster"> <div data-testid="card-text-wrapper"> <p data-testid="card-description">The foreign secretary's remarks come as the government...