Mbark Boussoufa struck as Morocco clinched top spot in Group D at the African Cup of Nations with a late 1-0 win over South Africa.
The Al-Shabab forward won it in stoppage time at the Al-Salam Stadium in Cairo on Monday.
Achraf Hakimi hit the crossbar for Morocco while Youssef En-Nesyri also missed a fine chance before Boussoufa pounced, which left South Africa's hopes of qualifying from the group in the balance.
Percy Tau shot wide for South Africa midway through the first half before Morocco took control of a dull game after the break.
The 1976 winners almost went ahead after 64 minutes when Hakimi's 25-yard strike rattled the underside of the bar.
Five minutes later, Morocco should have broken the deadlock only for En-Nesyri to miss a golden chance when he shot wide after rounding Ronwen Williams.
En-Nesyri also headed straight at Williams before Boussoufa fired in an 90th-minute winner after South Africa failed to clear a free kick.