Mali came from behind to beat African Nations Cup minnows Botswana in Libreville and set up a quarter-final against co-hosts Gabon.
Botswana took a shock lead shortly after half-time through Mogakolodi Ngele but Garra Dembele soon equalised and Seydou Keita curled home a sumptuous winner.
All eyes then turned to Guinea's clash with Ghana in Franceville, where the Black Stars held on for a draw to ensure Mali qualified at Guinea's expense.
Ngele fired well over from 20 yards early on before Mali missed a glorious chance, Modibo Maiga cutting the ball back to Dembele who headed over with the goal gaping.
The pitch was cutting up badly and an enormous divot in Botswana's left-back area was almost enough to trip up Mali's Abdou Traore.
Cedric Kante fouled Jerome Ramathlakwana to end a fluent Botswana move and following the resulting free-kick, defender Ndiapo Letsholathebe's backheel played in Lemponye Tshireletso, but he scuffed his shot wide.
Maiga's header was well off target and Traore's drive was blocked by Mogogi Gabonamong.
Drissa Diakite's cross almost caused problems but keeper Modiri Marumo managed to tip the ball away and an underwhelming first half ended goalless.
Ngele fired the Zebras into the lead with his first international goal five minutes after the restart, timing his run perfectly to meet Moemedi Moatlhaping's cross and sidefoot firmly home.
But Mali levelled six minutes later when Marumo parried Maiga's header but Dembele emphatically hammered home the rebound from close range.
They almost had a wonderful second when replacement right-back Ousmane Coulibaly slalomed through the defence and saw his shot rebound off the crossbar, with Maiga and Dembele combining to make a mess of the rebound.
The impressive Ngele turned and shot just wide at the other end before Keita curled home Mali's second. The Barcelona midfielder exchanged passes with substitute Cheick Diabate, just on for Dembele, and curled a measured first-time effort past Marumo with his left foot.
It remained 2-1 and, after a nervous wait for confirmation of Guinea's result, the Eagles' progression was confirmed.