Mohamed Salah was on target as Africa Cup of Nations hosts Egypt ensured they emerged from Group A with a perfect record despite a stern examination by Uganda.
Liverpool striker Salah's free-kick and a second goal from Aston Villa midfielder Ahmed Elmohamady before the break secured a 2-0 win.
But the scoreline flattered them on a night when Sebastien Desabre's side, who finished second in the group with four points and take their place in the last 16, gave as good as they got in Cairo.
Egypt keeper Mohamed El-Shenawy had made a number of good saves before Salah curled a left-foot free-kick over the wall and past 'keeper Denis Onyango in the 36th minute.
Skipper Elmohamady smashed home a second in first-half stoppage time to clinch a third successive victory for Egypt, all without conceding a goal.
Salah almost made it 3-0 early in the second half, only to be denied by Onyango, who is a doubt for the knockout phase after being stretchered off with 18 minutes remaining.
Madagascar surprise Group B winners
Africa Cup of Nations debutants Madagascar stunned Nigeria by beating the three-time champions 2-0 to confirm their place in the last 16 by surprisingly topping Group B.
Nigeria, who had already guaranteed their spot in the knockout phase prior to the game at the Alexandria Stadium, will need to improve significantly on this performance if they are to progress.
The Super Eagles fell behind in the 13th minute when Lalaina Nomenjanahary took advantage of a woeful defensive error from Brighton defender Leon Balogun to slot home after rounding goalkeeper Ikechukwu Ezenwa.
Despite dominating in terms of possession, Nigeria failed to record a shot on target in the first half and almost conceded a second just before the break, only for Madagascar captain Faneva Andriatsima to fire wide when through on goal.
Eight minutes into the second half, Madagascar sealed the win when Carolus Andriamahitsinoro's free-kick, following a foul on the edge of the area from Leicester midfielder Wilfred Ndidi, took a deflection and looped into the net.
DR Congo, Guinea made to wait
DR Congo and Guinea face an anxious wait to find out if they have a place in the last 16, with four of the six third-placed teams qualifying for the knockout phase.
DR Congo thumped Zimbabwe 4-0 in Cairo, with Zimbabwe's problems beginning just before kick-off when goalkeeper George Chigova was injured during the warm-up and Elvis Chipezeze stepping in for the Group A match.
Chipezeze's first meaningful moment after just four minutes was calamitous as his poor save in touching a relatively innocuous free-kick onto the crossbar allowed Jonathan Bolingi to score DR Congo's first goal of the tournament.
Eight minutes before the interval Cedric Bakambu fired home a precise finish before adding his second and his side's third from the penalty spot midway through the second half after being brought down by Chipezeze.
Middlesbrough striker Britt Assombalonga completed the rout 12 minutes from time for his first international goal, and courtesy of another error from the hapless Chipezeze.
Guinea also won their Group B game, beating Burundi 2-0. Guinea's cause was helped after just 12 minutes when Burundi were reduced to 10 men following the dismissal of Christophe Nduwarugira at Cairo's Al Salam Stadium.
Burundi, though, almost took the lead seven minutes later when Pierre Kwizera fired in a superb 30-yard effort that was tipped over by Ibrahim Kone.
Instead, it was Guinea who made the breakthrough in the 25th minute when Mohamed Yattara capitalised on a poorly-cleared corner to fire home from 18 yards.
Auxerre striker Yattara then clinched the three points with his second goal of the game seven minutes after the break.