South Africa survived a late penalty scare to knock pre-tournament favourites Morocco out of the Africa Cup of Nations and reach the quarter-finals.

Bafana Bafana were the better side and eventually ran out 2-0 winners over the 2022 World Cup semi-finalists – who had Sofyan Amrabat sent off in the closing stages after Achraf Hakimi had missed from the spot.

South Africa won just one group game to reach the knockout stages while Morocco had dominated Group F as they went in search of just a second AFCON title.

It was Hugo Broos’ side, however, who would hit the front as Evidence Makgopa finished off a flowing move with a low strike just before the hour.

Morocco toiled for an equaliser and were presented with the perfect chance to level from the penalty spot with just five minutes remaining.

A VAR check saw South Africa defender Mothobi Mvala penalised for handball but Hakimi smashed the resulting spot-kick against the crossbar.

Things went from bad to worse for Morocco as they chased the game, with Amrabat sent off for tripping Teboho Mokoena as he bore down on goal.

The Manchester United loanee thought he had been given a reprieve as VAR intervened but instead they recommended referee Mahmood Ismail upgrade the second booking to a straight red.

To add insult to injury, Mokoena dusted himself off to brilliantly convert the resulting free-kick and send South Africa into a quarter-final clash against Cape Verde.