Match ends, Senegal 0, Algeria 2.
Algeria reached the Africa Cup of Nations quarter-finals as Group C runners-up after beating Senegal.
Sofiane Feghouli missed a great early chance when his poor touch allowed Bouna Coundoul to save at his feet.
Leicester's Riyad Mahrez struck the opener when played in by a free-kick and Tottenham's Nabil Bentaleb drove in from 18 yards after the break.
Senegal were going through until Ghana's winner against South Africa put the Black Stars through instead.
It was a deserved victory for Algeria, who produced the more fluid football throughout despite not quite playing at their best.
Senegal will rue a shocking defensive lapse that gifted Algeria their opener and meant the Teranga Lions were always chasing the game.
The only negative for Algeria is an injury to key man Yacine Brahimi, who was forced off after 72 minutes - they will be hopeful the midfielder will be fit for Sunday's quarter-final against the winners of Group D.
Algeria finished second in the group behind Ghana, who claimed the top spot because of their superior head-to-head record, but may feel they might have been more ruthless.
They should have punished Papy Djilobodji's heavy touch in defence that put Feghouli clean though at the start of the match, and deep into the second half Taider's shot towards an empty net was cleared near the goalline.
But the Desert Foxes did enough to secure their passage, admittedly helped by a momentary lapse of concentration from Senegal, whose defence went missing for the opening goal.
A long diagonal free-kick into the box found Mahrez in acres of space and he controlled the ball with his left and slotted it past the keeper with his right.
Senegal's response was muted but they finally caused a problem when a sustained attack ended in Sadio Mane's shot being blocked and the follow-up scrambled clear.
On 53 minutes Senegal introduced substitute Papiss Cisse - the first participation at the tournament for the Newcastle forward - and his impact was almost immediate Mame Biram Diouf cut a ball back into box and it was just cleared off Cisse's toe as he took aim.
As Senegal pressed they almost grabbed a fortunate equaliser when the referee deflected an Algeria pass back to Mane but the Southampton striker slipped as he shot.
There was to be no escape for Senegal as on 82 minutes Tottenham midfielder Bentaleb finished off a swift counter-attack with a fierce angled drive into the bottom right corner to seal Algeria's win.
Senegal coach Alain Giresse:
"I am out of contract. My contract has finished.
"The road ends here for Senegal. There will be a lot of changes in and around the team. What happens next I don't know, but I know what I am going to do.
"We were not at our best. It was a strange match. Our performance was not up to what we could have expected."
- 12BadjiBooked at 41mins
- 13M'BengueSubstituted forSouaréat 29'minutesBooked at 81mins
- 5DiopSubstituted forCisséat 54'minutes
- 9DioufBooked at 67mins
- 10ManéSubstituted forN'Doyeat 66'minutes
- 4A N'Diaye
- 23M'bolhiBooked at 78mins
- 19TaïderBooked at 52mins
- 11BrahimiSubstituted forLacenat 72'minutes
- 7MahrezSubstituted forKashiat 90+2'minutes
- 15SoudaniSubstituted forBelfodilat 80'minutes
- Rajindraparsad Seechurn
- Shots on Target
Second Half ends, Senegal 0, Algeria 2.
Attempt blocked. Kara (Senegal) right footed shot from outside the box is blocked. Assisted by Idrissa Gueye.
Cheikhou Kouyaté (Senegal) wins a free kick in the attacking half.
Foul by Madjid Bougherra (Algeria).
Attempt missed. Saphir Taïder (Algeria) right footed shot from outside the box misses to the left. Assisted by Faouzi Ghoulam.
Corner, Senegal. Conceded by Carl Medjani.
Substitution, Algeria. Ahmed Kashi replaces Riyad Mahrez.
Attempt missed. Idrissa Gueye (Senegal) right footed shot from outside the box misses to the right. Assisted by Papy Djilobodji.
Kara (Senegal) wins a free kick in the defensive half.
Foul by Nabil Bentaleb (Algeria).
Attempt missed. Cheikhou Kouyaté (Senegal) right footed shot from outside the box misses to the left. Assisted by Idrissa Gueye.
Pape Souaré (Senegal) wins a free kick in the attacking half.
Foul by Sofiane Feghouli (Algeria).
Papy Djilobodji (Senegal) wins a free kick in the defensive half.
Foul by Ishak Belfodil (Algeria).
Attempt saved. Stephane Badji (Senegal) right footed shot from the right side of the box is saved in the centre of the goal. Assisted by Papy Djilobodji.
Lamine Sané (Senegal) wins a free kick in the defensive half.
Foul by Ishak Belfodil (Algeria).
Goal! Senegal 0, Algeria 2. Nabil Bentaleb (Algeria) left footed shot from outside the box to the bottom right corner. Assisted by Sofiane Feghouli.