Slick passing opened the Ahly defence and the midfielder struck the ball wide of goalkeeper Mohamed el Shenawy from closerange and into the far corner of the net.
The 28-year-old had been superb in Tuesday's match, until Marcus Berg nodded home the opener from closerange in the 51st minute. Shortly afterwards, De Gea sat down on the pitch, before being replaced by Kepa Arrizabalaga.
City, needing three points to become champions of England for the seventh time, took the lead just before half-time through Raheem Sterling's close-range strike.
The five-time Ballon d'Or winner converted a penalty in the 72nd minute, after a Ukraine player was judged to have handled a long-range shot in the box.
Messi opened the scoring with a pinpoint effort across Gianluigi Buffon on the stroke of half-time, while Ivan Rakitic finished from closerange after Messi's low cross was diverted away from goal on 56 minutes.
Tyrick Mitchell tapped in from closerange after a fine cross by Adam Wharton in the 58th minute and French youngster Olise capitalised on a Casemiro mistake to power a strike beyond a wanting Onana.
Pep Guardiola's side, taking part in the tournament after winning last season's Champions League, made the ideal start as Alvarez struck after 40 seconds, chesting in from closerange after Nathan Ake's long-range strike hit the post.
An eyewitness described the boy as having been shot at closerange, despite not being involved in the demonstrations. "This boy was not part of the protesters.
Adam Stahl badly miscued from closerange when Djurgarden had a chance to further cut the deficit. The result sees Enzo Maresca's men take a huge step towards booking their place in the May 28 final in Warsaw.