After three woeful group performances, South Africa were rank outsiders against the record seven-time African champions, whose line-up included Liverpool star Mohamed Salah.
A see-saw struggle was settled when a swift counterattack allowed Lebo Mothiba to send Lorch through and he fired past goalkeeper Mohamed Elshenawy.
The winners were unrecognisable from the team that struggled in the group stage as they displayed sharpness and desire not previously evident.
South Africa will face arch-rivals Nigeria, who eliminated defending champions Cameroon earlier on Saturday, in the quarter-finals.
Egypt changed three of the side that defeated Uganda to complete Group A with a 100 percent record, five goals scored and none conceded.