Thembinkosi Lorch scored five minutes from time to hand South Africa an upset 1-0 win and knock hosts Egypt out of the Africa Cup of Nations as the shock results at the competition continued on Saturday.
A seesaw struggle was settled when a swift counterattack allowed Lebo Mothiba to send Lorch through and score.
They take on South Africa on Saturday night, with current holders Cameroon set to kick off earlier than them against Nigeria.
Bafana scraped through to the last 16 by the skin of their teeth due to having finished as the fourth-best third-placed team.
South Africa will be without winger Themba Zwane, who is expected to serve a suspension against the North African giants.
Mohamed "Trezeguet" Hassan, one of the Pharaohs' stars in the group stage, tormented several defenders just outside the box and induced a foul, but Abdallah el Said botched the free-kick.
Egypt had the first clear chance of the second stanza and again it was "Trezeguet" who squandered a great opportunity: Mohamed Salah's defence-splitting pass picked out the Pharaohs' number seven, but he hit his shot straight at Williams in the 57th minute.
South Africa were looking the likelier side to break the deadlock and a courageous block by Ayman Ashraf foiled Lorch.
Egypt state that manager Javier Aguirre has opted to leave Salah out of his team's session to ensure that his "condition will not worsen", with reports indicating that he is suffering from illness.
Amr Warda, axed from the squad over sexual harassment allegations and swiftly recalled after player pressure, came off the bench on 64 minutes for his second tournament appearance.