Cameroon came from behind with two late goals to reach the last 16 of the 2023 Africa Cup of Nations, beating The Gambia in a thriller to knock their opponents out of the tournament.

The five-time champions secured second place in Group C on goals scored.

Rigobert Song’s side will next face Nigeria at Abidjan’s Felix Houphouet Boigny Stadium on Saturday (20:00 GMT).

The Scorpions looked to have dashed Cameroon’s hopes with a 91st-minute goal but it was ruled out for handball.

Guinea’s 2-0 defeat to group winners Senegal allowed Cameroon to move above them in the final table, although the Syli National will advance as one of the four best third-placed teams at the end of the group stage.

The Gambia failed to take a point from their campaign but the world’s 126th-ranked team – the lowest in the competition – were on course for a huge upset when Ebrima Colley curled them ahead for the first time from a tight angle with less than six minutes of normal time remaining.

Victory for Tom Saintfiet’s spirited squad would have put them in contention to go through among the third-placed teams and knocked Cameroon out, only for James Gomez to turn the ball beyond his own goalkeeper, Baboucarr Gaye, two minutes laterwhen the centre-back lunged in to attempt to intercept Enzo Tchato’s cross.

Having been on the brink of elimination, Cameroon climbed into second spot a minute into added time when Christopher Wooh rose to head a corner beyond Gaye’s dive and into the far corner of the net.

The abundance of late twists continued when Muhammed Sanneh – one of five changes made by Saintfiet – turned in a cross for a goal that was disallowed for handball by a VAR check.

There had been hints of the drama to come during a promising start by the underdogs, who are 80 places below Cameroon in Fifa’s rankings and reached the quarter-finals on their debut in 2021.

Cameroon head coach Song dropped Andre Onana in the most high-profile of four alterations to his starting line-up, restoring the Manchester United goalkeeper’s cousin, Fabrice Ondoa, in his place.

Ondoa was soon called into action, beating Ali Sowe’s angled strike away at his near post as part of an end-to-end first half in which the West African nation had the better chances.

Only a timely block by Jacob Mendy prevented Cameroon forward Karl Toko Ekambi from firing in a close-range shot on the turn, and Ondoa plunged on the recalled Yankuba Minteh’s effort when he was left unmarked at the far post to plant a header towards goal from Musa Barrow’s corner.

A spell of persistent Gambia pressure ended with Ondoa appearing to plead with his teammates to raise their defensive game, but Cameroon only noticeably improved after the break.

After Indomitable Lions forward Georges-Kevin Nkoudou hammered a shot against the crossbar five minutes into the second period, Toko-Ekambi headed Nkoudou’s searching delivery in six minutes later to break the deadlock.

The Gambia, however, soon levelled as Ablie Jallow arrived unmarked in the box to deftly volley in from Alieu Fadera’s cross.

Toko-Ekambi rattled the crossbar with a fizzing effort before Colley’s strike sent shockwaves around the Stade de la Paix, starting the sequence of three goals in six minutes to settle Cameroon’s destiny in an extraordinary finish.