South Africa, who had lost two of their three group games yet crept into the knockout stages, showed great improvement and were the more enterprising team, leaving 70,000 partisan fans stunned at the Cairo International Stadium.
Lorch finished off a sweeping counter-attack as South Africa, who created much the better chances, finally got an effort on target.
Absa Premiership Player of the Year Thembinkosi Lorch scored the only goal of the match in the 85th minute after receiving a killer pass, found himself one-on-one with the goalkeeper and drilled the ball into the bottom right corner.
Bafana did a superb job of keeping Liverpool star Mo Salah in check for the full 90 minutes.
Stuart Baxter's men will take on Nigeria in the quarter-finals on Wednesday, July 10 at 21:00 SA time.
Earlier, Nigeria ousted holders and bitter rivals Cameroon from the Africa Cup of Nations as they scored twice in three minutes to come from behind and win a thrilling last-16 match 3-2. The win earned Nigeria a quarter-final against Bafana Bafana.