Cameroon booked their place in the last eight after twice coming from behind to seal a 2-2 draw against Tunisia in Lubango.
Substitute Achille Webo, who came on as a second-half substitute, set up the goals for Samuel Eto'o and Celtic midfielder Landry Nguemo with perfect passes.
They will take on Egypt, who beat them in the 2008 final, in Benguela, while Zambia, who went through at the top of Group D on goals scored after beating Gabon 2-1, will face Nigeria in Lubango.
Tunisia, eliminated after drawing their three games, had gone ahead in the first minute through Amine Chermiti and again in the 63rd when defender Aurelien Chedjou netted into his own goal.
Gabon, Cameroon and Zambia all finished on four points, with Zambia winning a mini-league between them on goals scored (4), ahead of Cameroon (3) and Gabon (2).
Veteran Rigobert Song, whose blunders cost Cameroon two goals in their first two games, started on the bench, however, that did not prevent the Indomitable Lions from conceding the early goal.
The central defence was caught snoozing when striker Chermiti connected with a Khaled Souissi cross to head home after 50 seconds.
Cameroon piled on the pressure but proved too clumsy as Tunisia's back four held on.
Tunisia keeper Aymen Mathlouthi was lucky to escape a straight red card after denying Eto'o a clear chance when he handled the ball just outside the box on the half hour.
Although Cameroon enjoyed possession, Tunisia had another chance shortly before half-time when Yassine Mikari collected a through pass from Issam Jomaa but his shot went just wide.
Webo was brought on just after the break to replace midfielder Jean Makoun and the move immediately paid off as the Mallorca striker's pass found Eto'o, who coolly slotted home to level the contest in the 47th.
Centre-back Chedjou, however, lobbed his own keeper in an attempt to clear a Mikari cross as Tunisia regained the lead in the 63rd minute.
One minute later, Nguemo equalised for Cameroon when he fired past Mathlouthi from another Webo pass. Tunisia finished with ten men after defender Ammar Jemel was sent off for a second bookable offence.
Goals from Rainford Kalaba and James Chamanga earned Herve Renard's Zambia side a deserved 2-1 victory against Gabon in Benguela despite substitute Fabrice Do Marcolino's late consolation.
But it came at a price, with both Kabala and centre-half Kampamba Chintu collecting bookings which rule them out of the last eight clash.
Sunday, 24 January
Angola v Ghana (Luanda)
Ivory Coast v Algeria (Cabinda)
Monday, 25 January
Egypt v Zambia (Benguela)
Cameroon v Nigeria (Lubango)
Thursday, 28 January
Angola/Ghana v Cameroon/Nigeria
Ivory Coast/Algeria v Egypt/Zambia
Sunday, 31 January in Luanda