Cape Town - Bafana Bafana have lost 1-0 to Morocco in their Group D African Cup of Nations encounter in Egypt.
The result means that South Africa finish third in the group behind Ivory Coast - who beat Namibia 4-1 in their final group fixture - and Morocco.
Although some third placed teams will go through to the knock-out stages, South Africa's record of played three, won one and lost two means they stand very little chance of qualifying.
That, however, does depend on the outcome of matches later in the week.
It was Morocco who had the better start, spending much of the opening 10 minutes in possession. But whatever they threw at the South African defence was easily dealt with.
In the 16th minute, Ronwen Williams was called into action when he acted quickly to glove away a teasing cross into the South African box. Although South Africa had a number of corners, their first real chance came in the 33rd minute when Percy Tau let loose from outside the area only to see his shot just fly wide of the left-hand upright.
Morroco had an attempt straight after that but Younès Belhanda could only shoot straight at Williams.
The rest of the half remained a scrappy affair with Morocco bossing around 61% of the possession as the teams went into half-time at 0-0.
The second half followed much the same pattern as the first with Morocco having the lion's share of the possession.
Achraf Hakimi came close to breaking the deadlock in the 63rd minute when he unleashed a screamer from outside the box which left Williams stranded. Luckily for the South African keeper, the ball bounced back off the crossbar and the danger was cleared.
Youssef En-Nesyri was next to have an excellent opportunity to grab the lead as made his way into the area after collecting a through ball. Williams forced him wide of goal, however and although he touched the ball past the keeper, the angle was too great for him to slide the ball home for a goal.
The winner finally did come with just a minute left on the clock as Moubarak Boussoufa smashed a shot home from inside the Bafana penalty area.
In truth, it was a result Morocco deserved in a match they dominated.