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.
ga('create', 'UA-72310761-1', 'auto', {'name': 'pacontentapi'});
ga('pacontentapi.set', 'referrer', location.origin);
ga('pacontentapi.set', 'dimension1', 'By PA sport staff');
ga('pacontentapi.set', 'dimension2', '83d8b8b8-3d08-41b0-aa57-701ffeba2d78');
ga('pacontentapi.set', 'dimension3', 'paservice:sport,paservice:sport:football,paservice:sport:match-reports,paservice:sport:world');
ga('pacontentapi.set', 'dimension6', 'story');
ga('pacontentapi.set', 'dimension7', 'composite');
ga('pacontentapi.set', 'dimension8', null);
ga('pacontentapi.set', 'dimension9', 'sport:football');
ga('pacontentapi.send', 'pageview', { 'location': location.href, 'page': (location.pathname + location.search + location.hash), 'title': 'Morocco top Group D after late Boussoufa winner sees off South Africa'});