Mandla Masango of South Africa challenges Ghana’s Afriyie Acquah (L) during their 2015 African Cup of Nations Group C soccer match in Mongomo.

Algeria and Ghana advanced to the knockout round of the Africa Cup of Nations Tuesday, with the Desert Foxes winning a decisive 2-0 victory over Senegal Tuesday and the Black Stars beating South Africa 2-1.

Ghana ended the group stage atop Group C on goal differentials, even though Algeria is currently the top rated African side in the world FIFA rankings.

Algeria went ahead early, with a free kick in the 11th minute by Madjid Bougherra that went to an unmarked Riyad Mahrez who deftly sent a right-footed shot into the bottom right corner. Nabil Bentaleb added a second at the 82nd minute with a left-footed shot.

Ghana, meanwhile,came came from behind to send the South Africans packing. South Africa struck first, with Mandla Masango putting the Bafana Bafana ahead at the 17th minute with a 25-yard volley and spooking the Black Stars.

But John Boye gave hope to Ghana with a goal at minute 72, and an assist Marseille winger Andre Ayew, who then went on to score the decisive goal with a header at the 83rd minute on a cross from Baba Rahman.

Algeria and Ghana will take on the winner and runner-up of Group D on Sunday.