South Africa came from behind twice to draw 2-2 with Morocco on Sunday and top Group A in the Africa Cup of Nations.
Bafana Bafana (The Boys) finished on five points with Cape Verde, but a superior goal difference enabled the hosts to stay above the debutants, whose fairy-tale continued with a win over Angola in Port Elizabeth.
Issam El Adoua and Abdelilah Hafidi put the Atlas Lions ahead in this Indian Ocean city only for May Mahlangu and Siyabonga Sangweni to equalise and condemn Morocco to a fourth consecutive first round exit.
Cape Verde's dream run in the Africa Cup of Nations continued when they qualified for the quarter-finals thanks to a 2-1 win over Angola in a final-round Group A match.
Cape Verde's late goal saw them advance with the hosts.
Morocco and Angola were eliminated.
The west African islanders overcame mighty Cameroon to debut at the finals of Africa's showpiece football event, where they again impressed with draws against hosts South Africa and Morocco before coming from behind to beat the Angolans.
Angola were rewarded for their offensive play after 33 minutes when Amaro delivered a cross and Mateus put Neves under pressure with the ball coming off the Cape Verde skipper and into his own net.
Cape Verde restored parity in the 81st minute when Gege headed home after sustained pressure on Angola and Heldon won the game in the 90th minute as he fired home a rebound after Lama could not hold a fierce shot.
Late goals in both games changed everything in the final minutes as Cape Verde clinched their place in the last eight at the expense of Morocco who finished third and Angola fourth.