A last minute goal from Moubarak Mboussoufa gave Morocco a 1-0 win over South Africa in a Group D encounter played at the Al-Salam Stadium.
The loss for South Africa means they have to depend on other teams to do them a favor in order to qualify as one of the third best placed teams.
A point would have been enough for South Africa to progress and it was looking more likely but Mboussoufa had other ideas putting the ball past Ronwen Williams after the defenders failed to clear the danger from a set piece.
The win ensured that Morocco topped the group on 9 points while Ivory Coast make it through as runner-up with 6 points after coasting to a 4-1 win against Namibia.
Goals from Max Gradel, Serey Die, Wilfred Zaha and Maxwell Cornet gave the Elephants the much needed lift after their loss to Morocco in the second game.
Bafana Bafana are third in the group on 3 points but have dropped down the ranking table of the third best placed teams.
Stuart Baxter’s men will have to wait on other teams to learn their fate.
Namibia are eliminated with no point at all.