Starting the day looking to prevent Australia from retaining the Ashes, England got to 286-9, still 73 runs short of their target. The tourists needed only the win to ensure a series defeat was impossible and the urn would stay in their possession.
With one wicket left, England's World Cup hero Stokes knew everything depended on him and he smashed a remarkable eight sixes to all corners of the ground to get England within touching distance of their highest-ever second-innings total to win a test match.
Nathan Lyon missed an easy run-out chance to dismiss England number 11 batsman Jack Leach and Stokes survived loud lbw shouts, with Australia unable to review, before, fittingly, Stokes hit the winning boundary to spark euphoria at Headingley.
"Ben Stokes is a freak, he's incredible," England captain Joe Root said.
"To win a game on your own from there is just amazing. He does have recent experience of doing it. Just incredible to watch unfold."
England began the day on 156-3, still 203 short of what would be the second-highest ever fourth-innings run chase at Headingley.
Root, who played brilliantly to give England a chance coming into day four, chased an aggressive shot down the pitch only to edge to David Warner in the sixth over of the day, departing for a valuable 77.
Runs remained in short supply before a flurry of boundaries from Jonny Bairstow got fans off their seats.
A huge six from Stokes raised the decibel levels yet further on Headingley's famous Western Terrace, with England going into lunch in optimistic mood.
Bairstow was given out in the second ball of the afternoon session but the call was overturned following a review. He was eventually caught in the slips for a hard-earned 36, with the partnership worth 86.
A mix-up between Jos Buttler and Stokes saw the former run out for one before Stokes passed his 19th test 50 from 152 balls without even acknowledging the applause, such was his focus.
"I looked at the bigger picture," Stokes said. "There was still a lot of runs to get. Personal milestones, especially in that situation, mean absolutely nothing.
"It was all about making sure we got over the line."
Chris Woakes did not last long as he was caught for one, before Jofra Archer (15) was out looking for the big shot.
Stuart Broad was then out for a duck as all looked lost for England, before Stokes went into one-day mode, reverse sweeping for six, flicking another over wicketkeeper Tim Paine's head - there was no section of the stands safe from Stokes's hitting.
A big moment came when Stokes, on 116, hauled one out towards the boundary but did not get enough on it. Marcus Harris, on the dive, got two hands to it but put down the catch.
Leach's job was just to stay there, and he played his part, blocking ball after ball, contributing one run to the 76-run final partnership.
Stokes, in that time, plundered a mesmerising seven sixes in that final partnership, smashing a four through the covers to win the most dramatic of matches.
"We have time now to stick together and bounce back," Australia captain Tim Paine said. "If we get caught up in the emotion of it all then the series can be taken away from us quickly.
"The fact is we have been in a position to win every test match so far."
Australia 1st innings 179 (M Labuschagne 74, D Warner 61; J Archer 6-45)
England 1st innings 67 (J Hazlewood 5-30, P Cummins 3-23)
Australia 2nd innings 246 (M Labuschagne 80; B Stokes 3-56)
England 2nd innings (overnight 156-3, target 359)
R. Burns c Warner b Hazlewood 7
J. Roy b Cummins 8
J. Root c Warner b Lyon 77
J. Denly c Paine b Hazlewood 50
B. Stokes not out 135
J. Bairstow c Labuschagne b Hazlewood 36
J. Buttler run out (Head) 1
C. Woakes c Wade b Hazlewood 1
J. Archer c Head b Lyon 15
S. Broad lbw b Pattinson 0
J. Leach not out 1
Extras (b5, lb15, nb1, w10) 31
Total (9 wkts, 125.4 overs, 600 mins) 362
Fall of wickets: 1-15, 2-15, 3-141, 4-159, 5-245, 6-253, 7-261, 8-286, 9-286
Bowling: Cummins 24.4-5-80-1 (1nb, 1w); Hazlewood 31-11-85-4 (1w); Lyon 39-5-114-2; Pattinson 25-9-47-1 (4w); Labuschagne 6-0-16-0
Australia: David Warner, Marcus Harris, Usman Khawaja, Marnus Labuschange, Travis Head, Matthew Wade, Tim Paine (capt/wkt), James Pattinson, Pat Cummins, Nathan Lyon, Josh Hazlewood
Result: England won by one wicket
Player-of-the-match: Ben Stokes (ENG)
Series: Five-match series level at 1-1
Boult has taken 317 wickets for New Zealand in 78 Test matches, 62 wickets in Twenty20 cricket and is top of the one-day international bowling rankings
The hosts will now play Ecuador on November 20, 24 hours earlier than planned
The team will be based in Abu Dhabi
Men's team wins bronze in open section
His wife seeks compensation for snapshots of his corpse that were circulated after the helicopter accident
The tennis legend revealed impending retirement plans yesterday