Youcef Belaili fired Algeria into the last 16 of the Africa Cup of Nations with the only goal of a bad-tempered 1-0 victory over Senegal in Cairo.
There was particular frustration for Sadio Mane, whose reasonable shout for a second-half penalty fell on deaf ears as Algeria's physical approach proved the more effective method at the 30 June Stadium.
Algeria, through to the knockout stages for the first time since 2015, will win Group C if Tanzania fail to beat Kenya in Thursday's late game.
The north African side threatened to score twice in the first half, with Edouard Mendy making a diving save to keep out Belaili's free-kick in the 17th minute.
In stoppage time Baghdad Bounedjah, moments after heading wide, saw his shot parried wide by Mendy.
Belaili made the breakthrough shortly after the break when rifling home from the D following a rapid Algerian raid.
Liverpool star Mane thought had earned a spot-kick when he was double-teamed by two Algeria defenders, but the referee was not interested.
Rais M'Bolhi came to the Greens' rescue with a convincing stop against M'Baye Niang as time ticked away with Senegal continuing to push hard – Mane could only head over the bar at the death.