Minnows Cape Verde scored twice in the last nine minutes to stun Angola and seal their spot in the quarter-finals of the African Nations Cup.
Cape Verde, playing in the competition for the first time, looked to be heading home as they still trailed to a first-half own goal from captain Nando heading into the closing stages in Port Elizabeth.
However, Fernando Varela's 81st-minute equaliser gave them hope and then during a dramatic finale they snatched an historic victory thanks to substitute Heldon Ramos' stoppage-time finish.
The triumph means Cape Verde, who beat four-time champions Cameroon in the qualifiers, progress in second place in Group A behind host nation South Africa, with Angola and Morocco falling by the wayside.
Angola came into the match knowing only a victory would suffice after picking up just one point from their opening two matches, and they started the stronger.
Former Manchester United striker Manucho headed a Gilberto free-kick inches wide in the 11th minute before they got the breakthrough they were searching for in the 32nd minute.
Amaro was sent away down the left and his low cross was deflected into his own net by Nando as he challenged Mateus at the near post.
Cape Verde had been second best in the opening exchanges, but the goal sparked the competition's smallest nation into life and they really should have been level within three minutes but Julio Tavares headed wide from six yards.
Luis Platini also failed to hit the target with a header soon after, while Elvis Babanco saw his cross-shot turned behind for a corner by Angola goalkeeper Mamona Lama.
Angola were back on the attack at the start of the second half and Manucho struck a post, although the effort would have been ruled out for offside anyway, before Djalma saw a free-kick fly wide.
With time running out, Cape Verde began to turn the heat up on their opponents and Jorge Djaniny spurned a half-chance before the Blue Sharks drew level with nine minutes left on the clock, Verela nodding into the back of the net from close range following a corner.
With Morocco leading South Africa in the other group game, a draw here was not going to be enough to send either Cape Verde or Angola through to the last eight.
However, Cape Verde were given a boost when South Africa drew level, and Lucio Antunes' men then made sure of their progression when Heldon fired home after Lama had pushed out a low cross.