The hosts were quick off the starting blocks and they fired an early warning shot through Cristiano Ronaldo in the first minute, the Real Madrid star flashing an effort wide after collecting Raphael Guerreiro's pass.
Egypt gave as good as they got early on, and they tested Portuguese goalkeeper Beto in the seventh minute when Abdallah El Said shot towards the bottom corner, forcing the Goztepe man into a diving save.
The Pharoahs threatened again moments later when Liverpool ace Mohamed Salah was given too much space in the final third, but the free-scoring forward's effort ended up high and wide.
After a ropey start, Portugal took control of the match, but the Egyptian defence absorbed almost everything Ronaldo and his teammates threw at it.
Guerreiro was next to try his luck, narrowly missing the mark with a header in the 16th minute, while Wolverhampton Wanderers star Ruben Neves fired just wide of the top corner as the half-hour mark approached.
Portugal attempted to dictate play in the early stages of the second half and might have taken the lead had an offside flag not halted Ronaldo's advance as he latched on to Guerreiro's through-ball.
Egypt stunned their hosts moments later when El Said picked out Salah in the penalty area and the former Roma man did what he has done so many times for Liverpool this season, finding the bottom corner of the net with a left-footed drive.
Ronaldo had the chance to draw his side level just after the hour mark when he exchanged passes with Bernardo Silva and shot towards the bottom corner, forcing a reaction save out of Mohamed El-Shenawy.
Ricardo Quaresma was next to try for an equaliser, gaining possession inside the box and shooting first time, only for El-Shenawy to come to Egypt's rescue again.
Quaresma was the provider when Portugal's pressure finally paid off two minutes into stoppage time, the Besiktas winger supplying a cross for Ronaldo to nod over the line from close range.
Egypt, at this point, will have felt hard done by at the prospect of a draw, but things got worse for them two minutes later when Quaresma sent a free kick into the penalty area and Ronaldo headed his second-stoppage time goal to turn the game completely on its head.
PORTUGAL (4-4-2): Beto; Soares, Alves, Rolando, Guerreiro; Neves (Fernandes 76'), Moutinho (Gomes 61'), Mario (Quaresma 61'); A. Silva (Martins 68'), Ronaldo, B.Silva (Guedes 76')
EGYPT (4-3-3): El-Shennawy; Fathi, Gabr, Hegazi, Abdelshafy; Hamed (Ashour 87'), Elneny; Salah (Shikabala 79'), El-Said (Warda 66'), Trezeguet; Koka (Mohsen 62')