MONGOMO, Equatorial Guinea — Ghana produced a storming comeback and Algeria ratified its top ranking as both advanced to the African Nations Cup quarterfinals Tuesday with victories in their last Group C matches. Ghana was a goal down at halftime but beat South Africa 2-1 in Mongomo with two late strikes while Algeria ended Senegal's hopes with a 2-0 triumph in Malabo. Both finished on six points, and will play in the last eight in Malabo Sunday, but Ghanas top the group on the head-to-head result between the two. Andre Ayew rose majestically to head the winner seven minutes from time as Ghana produced a rousing second half showing after being 1-0 down to Mandla Masango's goal. The South Africa winger struck arguably the best goal of the tournament in Equatorial Guinea to give his side, which like Ghana needed a win to reach the last eight, the lead after 17 minutes. He struck a full volley from a standing position that looped over the head of Ghana goalkeeper Razak Braimah. A double switch from Ghana's new coach Avram Grant, who modestly refused to take any credit, galvanized its second half possession into two goals in 10 minutes and a second successive late win after Friday's triumph over Algeria. John Boye equalized in the 73rd as he was left unmarked to finish off a scuffed shot from Ayew, who then got onto the end of Christian Atsu's cross for the winner 10 minutes later. “It was called the ‘Group of Death' but we were alive with our spirit and our fighting ability,” said Grant. “The players gave 100 percent and we fully deserved it.” Senegal needed a draw to advance but its star-studded side crashed out to Algeria, which is the continent's top-ranked side. An early goal from Riyad Mahrez and a superb late strike by Nabil Bentaleb gave Algeria also two wins out of three in the group. They await Wednesday's conclusion of Group D to find out the identity of their quarterfinal opponents. Mahrez slotted beneath advancing Senegal goalkeeper Bouna Coundoul after 11 minutes to give Algeria the lead. Bentaleb fired into the corner of the net from outside the box in the 81st minute to make sure of their progress. Senegal finished with four points while South Africa was bottom of the standings with one. — Reuters