© AP Photos
South Africa eventually settled into the contest but they still went in trailing at the break.
Morocco picked up the baton once again in the second half and looked like extending their lead, only to be pegged back thanks to a wonderful strike by May Mahlangu.
He cut inside his marker before curling a shot past into a net.
Morocco were now staring down the barrel of elimination, but they were handed a lifeline when Abdelilah Elhafidi restored their lead with eight minutes remaining.
South Africa were not behind for long though, as Siyabonga Sangweni clipped a right-footed shot past a despairing Nadir Lamyaghri just four minutes later.