Algeria defeated Senegal 2-0 to send the west African side crashing out of the African Nations Cup finals after a tense clash in Malabo on Tuesday night.
Riyad Mahrez scored an early winner for Algeria, who finish second in the pool with six points having finished behind Ghana on head-to-head.
Senegal drop to third behind the Algerians after Ghana came from behind to defeat South Africa 2-1.
Algeria got an excellent second eight minutes from time as Nabil Bentaleb put the nail in the Senegalese coffin after they had gone into the final round of matches in pole position in the pool.
Algeria did not have it all their own way - for the 20 minutes before and after half-time they were put under severe pressure from the Senegalese.
But their greater experience and superior finishing ability saw them claim the win and set up a quarter-final meeting on Sunday with the top side in Group D.
The north African side should have been ahead inside two minutes when Sofiane Feghouli capitalised on a defensive mistake to race clear, but with just Senegal goalkeeper Bouna Coundoul to beat, he took a heavy touch at the vital moment and the chance was lost.
But they did have the lead on 11 minutes when a long ball to Mahrez found the forward in acres of space on the left-hand side of the penalty box and he coolly slotted the ball low past Coundoul.
Senegal lost the influential Cheikh M'Bengue on the half-hour mark as a knock to the face saw him leave the field dizzy and covered in blood.
There followed around 30 minutes of play that followed the same pattern: Senegal having all the possession and Algeria committing fouls 35 yards from their own goal.
The west Africans had close to 10 free-kick opportunities from that range, but could not find the right delivery or guile to break down the sturdy Algerian defence.
Sadio Mane had their best chance of the game when he received the ball just outside the six-yard box, but slipped at the vital moment.
The game was killed as a contest on 82 minutes when Bentaleb picked up the ball on the edge of the area and with no-one closing him down, fired in a low shot that had the beating of Coundoul.