It was a third successive one goal victory at the tournament for Morocco, who had already qualified for the last 16 and finished ahead of the Ivory Coast with South Africa third.
In a game of few chances, Boussoufa's instinctive finish settled the contest in Cairo on Tuesday, and sealed Morocco position at the top of Group D.
Watch the Africa Cup of Nations live on Eurosport and the Eurosport Player
Africa Cup of Nations
Late winner sends Nigeria into AFCON semi-finals
10/07/2019 AT 18:38
Achraf Hakimi smacked the crossbar after driving in from his left-back position to bend a right-foot shot onto the woodwork shortly after the hour-mark.
The game started at a languid pace as both sides adopted a cautious approach and were not prepared to be too expansive, lest they open up chances for the other.
It took more than 30 minutes for the first real effort as Percy Tau’s shot for South Africa went narrowly wide.
Morocco responded with a rasping strike from Younes Belhanda that went straight into the arms of goalkeeper Ronwen Williams
But Boussoufa scrambled in the winner in the final minute of normal time as South Africa failed to clear a corner and hooked his shot from close range over the line.
Morocco go through as Group D winners with nine points from their three games, while Ivory Coast sealed second spot after a convincing 4-1 win over bottom-placed Namibia.
Bafana Bafana rarely threatened to find a breath-through themselves, and with just three points from their three group games, they must wait to find out if that is enough to reach the round of 16.
The four best third-placed teams will progress, with Guinea confirmed having taken four points from their three games. DR Congo and Kenya are also on three points, while Benin and Angola have two points with one game remaining.
As the top team in the group, Morocco will play a third-placed side in the first of the knockout games on Friday
Africa Cup of Nations
Benin stun Morocco in shootout for historic win
05/07/2019 AT 15:17
Africa Cup of Nations
Egypt's Salah fit to face South Africa - team official
05/07/2019 AT 15:08