The opening goal arrived in the tenth minute when Issam El Adoua rose highest to head home from a corner, leaving the Bafana Bafana defence in disarray. Youssef El Arabi looked to grab a second goal in the tournament, having netted against Cape Verde, but Bongani Khumalo got in a crucial block on the Granada man's left-footed effort.
South Africa goalkeeper Itumeleng Khune did well to tip a low drive from Chahir Belghazouani around the post in the 20th minute and it suddenly seemed that Morocco had run out of ideas. Bernard Parker finally gave the home faithful something to cheer about with an effort from the edge of the area but his accuracy was lacking.
Hosts come out fighting
South Africa made a much brighter start following the break, though, with Thuso Phala forcing a fingertip save from Nadir Lamyaghri with his curling free-kick. Khune emerged victorious from a one-on-one with El Arabi on the hour mark and soon Bafana Bafana were in the ascendancy.
Gordon Igesund's men continued to make up ground and equalised in the 71st minute. May Mahlungu was unchecked on the edge of the Morocco box and his sumptuous curling finish sent the Durban crowd into raptures.
Hush descended, though, when Moroccan substitute Abdelilah El Hafidi chested down Zakarya Bergdich's cross to control and slotted home eight minutes from time. The hosts battled back, though, and centre-back Siyabonga Sangweni registered his second goal of the tournament when he put away the equaliser. The Orlando Pirates man found himself on the edge of the box with four minutes to go and twisted his body to clip the ball across Nadir Lamyaghri and into the bottom corner.
The result, combined with Cape Verde Islands surprise win over Angola, means South Africa will have the more favourable draw heading into the quarter-finals.