10 minutes after the restart, Salah released Trezeguet behind South Africa's backline with a defence-splitting pass, but his first-time shot was saved steadily by Ronwen Williams.
South Africa's player celebrate their opening goal during the 2019 Africa Cup of Nations (CAN) Round of 16 football match between Egypt and South Africa at the Cairo International Stadium in the Egyptian Capital on July 6, 2019.
The stunning elimination marked Egypt's worst-ever performance as hosts.
Egypt will lock horns with South Africa on Saturday as they enter the knockout stages of the continental competition, but whether or not they will have Salah at their disposal remains to be seen.
Nigeria earlier beat defending champion Cameroon 3-2 in a wild last-16 game.
The Pharaohs wasted a glorious chance just two minutes later.
South Africa made two changes, both in midfield, from the team that lost to Morocco and squeezed into the second round with the worst record of the best four third-place teams.
Tau came much closer to breaking the deadlock midway through the half with a free-kick that cleared the wall and forced Elshenawy into a brilliant save.
South Africa progressed to a quarterfinal against Nigeria, while Egypt and Salah were left bitterly disappointed with an early exit from their home tournament.
But Egypt could have still taken the lead had it not been for a surprise miss from Trezeguet, one of the team's standout performers of the tournament.
Salah, who has had a cold, was told by Egypt coach Javier Aguirre not to "worsen his condition" by training.
The match looked set for extra time, but on 85 minutes South Africa struck on a quick counter attack: Lebo Mothiba beautifully played in Lorch, who this time showed great composure to slide a shot beyond the 'keeper and provide the decisive moment.
Meghan Markle cheers on Serena Williams at Wimbledon
She was photographed there with Genevieve Hillis and Lindsay Roth , two of her friends from Northwestern University. Murray and Williams practised for the first time together yesterday, in front of family and journalists.