Cameroon lost top spot in Group F to Ghana, which overcame an unimpressive start to the tournament to beat Guinea-Bissau 2-0 when it really counted. Ghana's first win in Egypt came via second-half goals by Jordan Ayew and Thomas Partey and put the Black Stars back on track.
The last 16 lineup has now been decided and the most compelling match-ups alongside Cameroon vs. Nigeria are: Host Egypt and Mohamed Salah vs. South Africa, Sadio Mane's Senegal vs. Uganda, and Ghana vs. Tunisia. Surprise package Madagascar, playing at its first African Cup, must beat Congo to take its strong run into the quarterfinals.
Ghana, a four-time champion, was under threat of not qualifying at all. But Jordan Ayew's splendid solo goal a minute after halftime against Guinea-Bissau in Suez settled the nerves and Thomas Partey poked in a cross from close range in the 72nd to make sure of progression. Ayew broke down the left wing, skipped past a defender and curled a right-foot shot high into the far corner of the goal.
Ghana won the group ahead of Cameroon on goals scored after both finished with a win and two draws. Tuesday's victory was the first real piece of good news at the tournament for Ghana, which started with two draws and this week learned it had lost influential winger Christian Atsu for the rest of the tournament with a hamstring injury.
Clarence Seedorf's Cameroon made life difficult for itself by missing out on first place in the group. Benin's reward for the draw with the title holder in Ismailia was a place in the knockouts at the African Cup for the first time.
Benin squeezed in as one of the four best third-place teams. Mali won Group E, the last group to be wrapped up, with a 1-0 win over Angola. The 21-year-old midfielder Amadou Haidara scored late in the first half with a powerful left-foot shot that swerved into the top corner and gave Angolan goalkeeper Tony Cabaca no chance.
Striker Moussa Marega should have made it comfortable for Mali when he chested a corner down in the 90th minute but sliced his shot wide. Tunisia was the last team to go through after drawing 0-0 with Mauritania, another team making its African Cup debut.
More AP soccer: https://apnews.com/apf-Soccer and https://twitter.com/AP_Sports