Ahly continued their recent mini-revival after some patchy displays virtually ended their league hopes as they vie with Pyramids FC for a runners-up spot.
Some youngsters propelled them to an impressive 3-0 win over Ittihad in their previous match but Portuguese coach Ricardo Soares surprisingly opted to pick the old guard for the game against Masry.
Winger Zeyad Tarek and striker Ahmed Gharib, who scored Ahly's goals against Ittihad, started on the bench as the Red Devils struggled to break down Masry in a low-tempo first half.
They improved in the second though but needed an 80th-minute penalty from central defender Ramia to break the deadlock. He sent the keeper the wrong way after Hassan was caught in the heel by a Masry defender as both men tussled for a long ball.
Hassan then finished off a well-worked breakaway six minutes into stoppage time to ensure the win as Ahly avenged their 1-0 loss to Masry in April.
Midfielder Mohamed Mahmoud started the move, feeding Hassan on the edge of the area to superbly exchange passes with full-back Mohamed Hani, break clear and fire a low shot into the bottom corner.
Hassan fared much better than Salah Mohsen, the forward who started the game but was disappointing throughout. Mohsen missed a sitter in the first half when he raced clear, only to send a tame effort into the keeper's hands.
Masry offered little in attack but were infuriated after having a late equaliser chalked off for offside.
Ahly keeper Ali Lotfi also foiled burly striker Austin Amutu in a one-on-one, with Abdel-Latif Grendo blasting the rebound high over.
The Red Devils are third in the table with 62 points but can pull level with second-placed Pyramids if they win their game in hand. Zamalek top the table with 72 points and will be crowned champions if they win two out of their last four matches.
(For more sports news and updates, follow Ahram Online Sports on Twitter at @AO_Sports and on Facebook at AhramOnlineSports.)