Reigning champions Ivory Coast crashed out of the Africa Cup of Nations as they were beaten 1-0 by Morocco, who advanced to the last eight thanks to Rachid Alioui's superb second-half winner.
Only on the field due to Aziz Bouhaddouz's first-half injury, Alioui's excellent strike was the difference as the Elephants failed to reach the knockout stages for the first time since 2002 following an insipid performance in Tuesday's meeting in Oyem.
Herve Renard led Ivory Coast to their triumph two years ago but, now in charge of Morocco, the Frenchman watched on as his new side qualified second from Group C behind DR Congo.
Knowing they needed a win to advance, the defending champions saw chances come and go for Wilfried Zaha and Salomon Kalou, but they could not find a way through a stubborn Morocco backline well marshalled by Bayern Munich's on-loan Juventus defender Medhi Benatia.
Morocco went close in the first half when Faycal Fajr struck the woodwork with a set piece and, with DR Congo defeating Togo 3-1 elsewhere, the Atlas Lions knew a draw was enough to see them through to the quarter-finals for the first time since 2004, when they finished runners-up.
But Renard's side were not satisfied to sit back and hold out, and were rewarded midway through the second period when Alioui curled home a delightful winner from distance.
The holders had the better of the opening exchanges without carving out any opportunities, but it was Morocco who went agonisingly close to opening the scoring in the 25th minute.
Following Cheick Doukoure's foul on Bouhaddouz, Fajr's curling free-kick over the wall crashed against the crossbar with goalkeeper Sylvain Gbohouo beaten.
The Elephants' first real chance arrived in the 37th minute when Zaha's effort from the left-hand side of the box was parried away by Munir.
Kalou created that opening for Zaha and the Hertha Berlin forward went close himself shortly before the break, heading against the outside of the post from a tight angle.
Gbohouo made an uncertain start to the second period but his flap from a long free-kick into the area went unpunished by Morocco captain Benatia, who lifted the ball over the unguarded goal from 20 yards.
But the Elephants' keeper had no such luck in the 64th minute as Alioui picked up a pass from Youssef En-Nesyri and, with Simon Deli backing off, curled a marvellous effort over Gbohouo from 25 yards.
Hamza Mendyl wasted a chance to wrap it up for Morocco when he fired into the side-netting with 10 minutes remaining, but it mattered little as Renard celebrated a success over his former employers.