Djamel Belmadi’s side, who needed a win to guarantee progression to the last 16, had plenty of chances to open the scoring early on, as Youcef Atal and Adam Ounas both had shots saved.
Their best opening fell to Houssem Aouar, although he failed to hit the target from close range, squeezing the wrong side of the post when he ought to have done better.
At the other end, Mauritania grew into proceedings, and after Souleymane Anne had forced a terrific stop out of opposition goalkeeper Anthony Mandrea, they took a shock lead through Dellahi.
The Al-Nasr midfielder profited from Omare Gassama’s blocked shot falling his way, coolly hooking home via the inside of the post from 10 yards out. Hitcham Boudaoui then spurned a pair of openings for the Greens before the break, while Aboubakary Koita had a fierce effort beaten away.
Leading at the break, Amir Abdou’s side were on course for their first ever AFCON victory, and they knew a win would see them qualify as one of the tournament’s best third-placed finishers. Algeria, on the other hand, were heading out, and called for the cavalry as Riyad Mahrez was finally introduced for the second period.
They nearly found themselves 2-0 down, though, when a mazy Koita run, which took him past several defenders, ended in a blazed shot over the bar.
At the other end, Babacar Niasse made a pair of stunning saves to keep out Boudaoui’s flicked header and Aïssa Mandi’s point-blank range effort as the Greens started to throw the kitchen sink at their opponents.
As Algeria piled forward, space was left at the back, which was nearly exploited by Aboubakar Kamara, who had a long-range shot palmed to safety, while Ibnou Ba missed an open goal, rattling the woodwork from yards out.
Those squandered chances mattered not, though, as Mauritania registered a fairytale victory – their first-ever against Algeria – who fail to qualify for the knockout stages for the second tournament running.