Substitute Abdallah El Said struck an 89th-minute winner to seal a 1-0 victory over Uganda and boost Egypt's hopes of reaching the African Nations Cup knockout stages.
El Said's effort means his team will head into Wednesday's final Group D clash with already-qualified Ghana needing just a point to progress, while Uganda are eliminated.
Egypt made the better of appalling pitch conditions in Port-Gentil to dominate the early exchanges as they looked to improve on their disappointing opening draw against Mali.
Ramadan Sobhi caused early problems and almost set up a good chance for Trezeguet, while former Chelsea star Mohamed Salah also looked sharp.
Tarek Hamad fired just over the bar in the 33rd minute but the Ugandans slowly got to grips with proceedings and stemmed the one-way flow before half-time.
Joseph Ochaya put the ball in the net for Uganda after 55 minutes but it was ruled out for offside, while keeper Denis Onyango made two comfortable saves to deny Trezeguet.
Uganda were seldom posing much of a threat to the Egyptian defence but they were coping well at the back and restricting the favourites to few clear chances in front of goal.
But as the minutes ticked by Egypt managed to apply more pressure and Marwan Mohsen came close to grabbing the opener when he headed over in the 73rd minute.
Just when Uganda thought they had done enough to hold out, El Said, a 59th minute replacement for Hamad, pounced on the counter-attack to sweep the winner past Onyango.