Abdallah el-Said scored a last-minute winner to give Egypt a 1-0 victory over Uganda in African Nations Cup Group D on Saturday and eliminate the East Africans from the competition.
Egypt moved into second place in the standings on four points as they finally ended their goal drought at the tournament.
Said was set up by Mohamed Salah just when it seemed the Egyptians were going to be held to a second successive draw, blasting through the legs of the Uganda goalkeeper Denis Onyango.
Uganda, without a point, cannot go through to the next round with one game still to play.
Egypt began the match with a much-improved tempo after a cautious approach in their opening game against Mali, laying early siege to Uganda's goal.
Uganda, who last competed at the Nations Cup finals 39 years ago, stood firm, however, and found confidence in midfield after initially giving away a lot of possession.
But there was always the threat of the speedy Salah. He showed his ability with a superb pull down before transferring the ball from right to left foot midway through the first half but his resultant shot from close range was blocked.
Uganda had the ball in Egypt's net in the 51st minute but Joseph Ochaya was offside when he finished off an in-swinging cross.
Marwaan Mohsen and Mohamed Trezeguet created half-chances for Egypt but still could not forge a breakthrough until their last-gasp goal.
Egypt finish their group campaign on Wednesday in Port Gentil against Ghana, who have already qualified. Uganda face Mali.
Earlier on Saturday, Ghana beat Mali 1-0 to secure a quarter-final berth.