South Africa are staring at an Africa Cup of Nations exit following a late 1-0 loss to Morocco in their final Group D game on Monday.

Bafana Bafana needed a win to guarantee their place in the last 16 but were beaten thanks to Moubarak Boussoufa's strike, allowing Ivory Coast to progress in second place in their stead thanks to a 4-1 defeat of Namibia.

Morocco were already sure of a place in the next round and always looked the more likely to find a breakthrough, with Achraf Hakimi rattling the crossbar in the second half before Boussoufa's 90th-minute goal.

They progress as group winners with nine points, while South Africa will have to wait to see if they have done enough to advance as one of the four best third-placed teams.

Younes Belhanda came close to an opener in a dour first half in which South Africa offered little sign of scoring what would have been just their second goal of the tournament.

Thamsanqa Mkhize dragged a shot narrowly wide in a positive start to the second half, but it was Morocco who began to look more likely to score even after news of Ivory Coast's two-goal lead over Namibia must have begun to filter through.

Achraf was inches from a spectacular opener, his thunderous strike from 25 yards smashing off the underside of the crossbar and bouncing clear, before Youssef En-Nesyri failed to convert after rounding goalkeeper Ronwen Williams.

South Africa applied some late pressure to no avail and were undone when Boussoufa smashed a half-volley into the top-right corner after Stuart Baxter's men failed to clear their lines.