Just days after a late goal helped Ghana beat Algeria, ex-Chelsea coach Avram Grant enjoyed another dramatic show as Andre Ayew's 83rd minute goal led his side to a 2-1 victory over South Africa.
The result means The Black Stars, who are four-time champions, advance to the knockout rounds as Group C winners.
However, it all seemed so different early on South Africa took the lead when Mandla Masango volleyed in from long range.
But John Boye levelled for Ghana, before Ayew headed in seven minutes from time.
Algeria join Ghana in the quarter-finals as group runners up after they picked up a 2-0 win against Senegal.
Leicester's Riyad Mahrez opened the scoring on 11 minutes, before Tottenham's Nabil Bentaleb made sure of all three points 10 minutes from time.