Ahly's Amr Gamal celebrates scoring their first goal with team mates (Reuters)
Ahly scored two goals late in extra time in typical fashion to come from behind and earn a dramatic 2-1 victory over Masry, which gave them their first Egypt Cup title in 10 years and completed a domestic double.
Substitute Amr Gamal, who will join South Africa's Bidvest Wits on loan, enjoyed a perfect send-off by heading home and creating another goal for veteran right-back Ahmed Fathi in the last four minutes of extra time to break the hearts of a brave and spirited Masry side and give Ahly a record-extending 36th cup title.
Attacking midfielder Abdallah Bika gave Masry a surprise lead with a hopeful shot in the first half of extra time but Masry coach and Egypt's all-time leading scorer Hossam Hassan was denied his first title in his managerial career following Ahly's impressive late comeback, which has been a hallmark of the Cairo giants for over 10 years.
Ahly last won the oldest club competition in Egypt in 2007 when they beat Cairo rivals Zamalek 4-3 in a thrilling clash. They lost to their bitter foes in the previous two finals.
Masry also missed out on only their second title in history, having won the Egypt Cup in 1998.
Ahly will now turn their attention to the African Champions League as they eye a memorable treble. They will face Tunisia's Esperance in a mouthwatering two-legged quarter final next month.
Neither side were able to gain the upper hand in a cautious first half, despite a surprise bold approach by a physical Masry side.
Instead of sitting back to soak up any pressure, Masry opted to push forward whenever they had the ball, albeit with mild threats.
The only real opportunity of a dour first half fell to Ahly's winger Moemen Zakareya, who sent an angled shot narrowly wide from inside the area after a three-man move in the 18th minute.
Ahly's key players, including playmaker Abdallah El-Said, were well shackled by Masry's rearguard which was barely breached.
The second half was also dull but Ahly slightly improved, wasting a couple of chances as Masry began to tire after failing to keep up their superb work rate.
Masry were also forced to make an unscripted substitution when in-form central defender Ahmed Mansour picked up what looked a serious injury. He was replaced with Abdallah Bika.
Ahly's lone striker Junior Ajayi was guilty of spurning the best chance seven minutes past the hour mark when he was found unmarked by a pull-back from Zakareya, only to see his shot strike the legs of keeper Ahmed Buska from eight yards out.
Zakareya also volleyed high over when well positioned to score following a chipped free kick from El-Said five minutes from time.
In extra time, Masry caught Ahly by surprise when substitute Bika scored in the 102nd minute with a right-foot shot that went into the corner of the net past sprawling keeper Sherif Ekramy.
Ahly poured forward en masse, wasting some easy chances until Gamal rose above his marker to head home an inswinging corner from Tunisian left-back Ali Maaloul in the 117th minute.
The final drama unfolded just before the final whistle when a quickly-taken throw-in saw Gamal feed Fathi with an astute pass in the area to send a delicate chip over the advancing keeper, sparking wild celebrations on the field.
Masry's players fell to the ground in agony following the end, with Ahly celebrating a triumph that has eluded them for 10 years.
(For more sports news and updates, follow Ahram Online Sports on Twitter at @AO_Sports and on Facebook at AhramOnlineSports.)