Bafana Bafana opened the scoring through Mandla Masango, but the Black Stars deservedly hit back after the break through strikes from John Boye and Andre Ayew.
The west Africans advanced to the quarter-finals as Group C winners along with Algeria, who beat Senegal 2-0 in a simultaneous fixture.
Shakes Mashaba's men ended bottom of the pool with a point from three games - three points shy of Senegal, and five behind the top duo.
Tournament hosts Equatorial Guinea, Congo-Brazzaville, DR Congo and Tunisia previously qualified for the last-eight.
Ghana had a great chance six minutes in, as Mulomowandau Mathoho was forced to clear of the line to deny Jordan Ayew on the rebound after Brilliant Khuzwayo spilled an initial shot from the Lorient attacker.
Eleven minutes later Masango gave South Africa the lead, against the run of play, with a thunderous 22-yard volley that beat the keeper hands down.
Despite the shock of going behind Ghana continued to push forward and nearly levelled matters in the 34th minute when Baba Rahman unleashed a powerful shot from 35-yards, but he saw his effort well-saved by the keeper.
Two minutes later Ghana suffered a bit of a set-back when Daniel Amartey had to leave the field injured and was replaced by Boye.
South Africa came close to finding their second five minutes before the break when Bongani Ndululu met a right wing cross from Anele Ngcongca, but his header was saved by the fingertips of the keeper.
The second half was all Ghana and it was only a matter of time before they equalised.
That goal came in the 73rd minute after Boye fired the ball home from 12-yards out after a goalmouth scramble.
Ten minutes later Ayew scored the winner for Ghana when he headed home a left-wing cross from Baba Rahman.