Algeria crashed out of the 2023 Africa Cup of Nations as minnows Mauritania claimed a famous first ever win at the finals to snatch a spot in the last 16.
Centre-back Yali Dellahi swept home the winning goal late in the first half to stun the two-time Afcon winners.
Defeat means 2019 champions Algeria exit the tournament at the group stage for the second successive edition.
They finish bottom of Group D while Mauritania will definitely progress as one of the best third-placed teams
Mauritania will face surprise Group B winners Cape Verde in the last 16 at Felix Houphouet Boigny Stadium in Abidjan on Monday (17:00 GMT).
Algeria join fellow former champions Ghana in being eliminated after results earlier on Tuesday meant the Black Stars, with just two points to their name, cannot qualify as one of the top four third-placed sides.
The Lions of Chinguetti had to withstand late pressure and survive more than 11 minutes of stoppage time as Algeria sought a leveller that would have sent them through at Mauritania’s expense.
But the underdogs were good value for a victory that sent them into the knock-out stages alongside second-placed Burkina Faso and Angola, who sealed top spot in the group by beating the Burkinabe 2-0.