The 18-year-old leg-spinner claimed figures of 5-48 as Pakistan were bowled out for 216 on day three in Karachi, leaving England with a target of 167 to complete a 3-0 series victory.
England started their chase in a manner that epitomised the attacking brand of cricket that has been played by the team since Ben Stokes and Brendon McCullum took charge as they raced to 112 for two at stumps.
That left the tourists requiring just 55 more runs to win on day four, with Ben Duckett (50) and Stokes (10) unbeaten at the crease.
It was the introduction of teenager Ahmed in the afternoon session that helped turn the momentum England's way, however.
He broke a 110-run partnership between Babar Azam and Saud Shakeel that had looked to have given Pakistan a lifeline after Jack Leach (3-72) had earlier reduced the host to 54 for three.
Ahmed then followed up his key dismissal of Pakistan captain Babar for 54 with two more vital breakthoughs - those of Mohammad Rizwan (seven) and Saud Shakeel (53) - as Pakistan slumped from 164 for three to 177 for six at tea.
Ahmed then picked up where he left off in the evening session with two more wickets to complete his five-fer as the hosts were bowled out for 216.
Not only did Ahmed write his name into the history books as the youngest men's Test debutant to claim five wickets in an innings, he also easily surpassed the record for the youngest Englishman to take five in an innings.
Ahmed was more than two years younger than the previous England record-holder Bill Voce, who was aged 20 years and 177 days when he achieved the same feat in 1930.
There have been other players to take five wickets in a Test innings at a younger age however, with Ahmed sitting sixth on the list, pushing current Australia captain Pat Cummins down seventh.
Following Ahmed's efforts, England's chase started in breathtaking fashion as the required total was rapidly chopped to 80 before Zak Crawley was out lbw having hit 41 runs from as many balls.
Ahmed was sent in at number three in an attempt to push the scoring along but he made only 10 before being bowled by Abrar Ahmed, and looked furious with himself, hitting the bat on his way off the field.
Stokes pushed himself up the order to number four, and played an entertaining innings that included inadvertently launching his bat almost to the feet of the square leg umpire in an attempt to find a boundary for England.
He will begin on Tuesday morning alongside Duckett, who made an unbeaten 50 off 38 balls.
While Ahmed took the plaudits later on, it was his fellow spinner Leach who made inroads for the tourists in the morning session, taking three wickets in six balls.
Pakistan started the day with a four off the first ball and 12 from the opening over, but were soon forced to go more defensive after Leach struck.
Shan Masood was bowled for 24, attempting a reverse sweep, which brought Azhar Ali to the crease for his final innings in Test cricket.
It finished in disappointment for the 37-year-old though as he was bowled by Leach for a four-ball duck before leaving the field to a guard of honour. Abdullah Shafique was Leach's third and final wicket.