PORT ELIZABETH, South Africa (AP) -- Cape Verde joined host South Africa in the quarterfinals of the African Cup of Nations on Sunday after the small island nation scored two late goals to secure advancement in its first appearance in the tournament.
Cape Verde netted an injury-time winner through Heldon Ramos to come from behind and advance with a 2-1 victory over Angola, preventing the Angolans from stealing through from last place in the group.
Siyabonga Sangweni's 87th-minute equalizer kept alive the nervous home team as South Africa twice came from behind in a 2-2 draw with Morocco, avoiding an early elimination and knocking out the disappointed Moroccans.
South Africa finished top of the group on goal difference and Cape Verde was second, with Ramos' powerful shot prolonging their entertaining stay at their first major tournament.
South Africa sighed with relief, while Cape Verde erupted with joy after continuing to overachieve on its first visit to the Cup of Nations.
"Today we came here to win the game. There was no chance we could even consider a failure,'' Cape Verde coach Lucio Antunes said after his players had all burst into the news conference room to sing and dance and chant in front of reporters.
Morocco and Angola both gave up leads late to be eliminated, with Morocco coach Rachid Taoussi and some players in tears afterward as they went from topping the group to being out of the tournament in three painful minutes.
"We did not lose, no. Repeat, no loss,'' said Taoussi, who cried during the post-match news conference. "We did not qualify, OK, but not a loss.''
Substitute Ramos hammered his shot into the roof of the Angolan net following a parry from goalkeeper Lama and after the clock had ticked past 90 minutes at Nelson Mandela Bay in Port Elizabeth, leading to chaotic celebrations as the entire Cape Verde squad and coaching staff ran onto the pitch to bury Ramos under a pile of bodies near the corner flag.
Antunes did a lap around the pitch after the final whistle waving the blue flag of his country.
Sangweni's strike from near the edge of the area allowed home fans at Durban's Moses Mabhida Stadium to breathe again after Bafana Bafana was almost out and nearly left to face a wave of bitter disappointment from the home country.
"We had to dig really deep for the result today,'' South Africa coach Gordon Igesund said. "It was very important for us to qualify (for the quarterfinals), hosting this tournament, and I think we've made the country proud.''
Goals from Issam El Adoua and substitute Abdelilah Hafidi appeared to have put Morocco through to the last eight for the first time since 2004. But on both occasions South Africa fought back, with May Mahlangu and Sangweni ensuring the host went through.
Cape Verde captain Fernando Neves' own goal in the 33rd had his team trailing and gave Angola its first goal of the tournament, but Fernando Varela equalized in the 82nd from a header after a goalmouth scramble.
The tiny island nation was still out until Ramos' goal backed up Antunes' assertion all through the campaign that his team was good enough to be taken seriously at Africa's top tournament.
"The objective is completed,'' Antunes said. "We came here to win the game and we've done it. Now we're down to the quarterfinals.''