Former champions Algeria crashed out of the Africa Cup of Nations on Tuesday after losing 1-0 to Mauritania, who are 75 places lower in the world rankings.
Captain Mohamed Delllah Yaly scored after 37 minutes in Bouake for the Group D outsiders, who will fill one of four places reserved for third-placed finishers in the mini-league stage.
Angola defeated Burkina Faso 2-0 in the same section and topped the final standings with seven points. Burkina Faso (four) and Mauritania (three) also advanced to the knockout stage.
Champions in 1990 and 2019, Algeria came to the Ivory Coast among the favourites to win the African football showpiece only to depart without winning a match.
After draws with Angola and Burkina Faso, they were stunned by Mauritania, who had never won a Cup of Nations match in eight previous attempts spanning three editions.
The winners were constantly on the back foot, especially in the closing stages, but showed defensive resilience to pull off a famous victory.
Former Manchester City winger Riyad Mahrez arrived in west Africa as the standout Algerian, but poor performances in his first two matches saw him relegated to the bench for this match.
“It’s a fact that these have not been his best matches with Algeria, but don’t kill him too soon,” pleaded coach Djamel Belmadi before facing Mauritania.
The absence of Mahrez did not affect the Desert Foxes unduly for much of first half as they camped in Mauritanian territory seeking to break the deadlock.
Houssem Aouar connected with a low cross midway through the half and his sidefooted goal attempt flew narrowly wide.
Against the run of play, Mauritania took the lead on 37 minutes just after goalkeeper Anthony Mandrea conceded a corner having used his leg to block an Aboubakary Koita shot.
Algeria failed to clear the corner and when the ball returned to the area, Iraq-based captain Dellah Yaly struck the ball into the net off a post.
It was not the cleanest of strikes, but that did not matter as wild celebrations erupted after the underdogs took the lead in a Cup of Nations match for the first time.
Algeria responded by putting pressure on the Mauritanian defence again and Hicham Boudaoui was not far off target with a shot from just outside the box.
Belmadi turned to Mahrez, now playing in the lucrative Saudi Pro League, at half-time, bringing him on in place of Aouar to confront tall, well-organised opponents.
Koita squandered a chance to double the lead just before the hour mark, dribbling into the box before blazing over to the relief of Mandrea.
Almost immediately, Bodda Mouhsine was guilty of equally wild finishing from close range, after a Koita free-kick was deflected into his path.
At the other end, a perfectly weighted Mahrez cross led to a Boudaoui header being superbly tipped over by goalkeeper Babacar Niasse, who later foiled Aissa Mandi from point-blank range.
Download our app and read this and other great stories on the move. Available for Android and iOS.