England, bowled out for just 67 in their first innings, needed 73 more runs to reach a victory target of 359 when last man, the bespectacled Jack Leach, came into bat on the fourth day.
But Leach held firm before Stokes, the batting hero of England's World Cup final triumph, hit the winning runs by flaying paceman Pat Cummins for a four that saw the all-rounder finish on 135 not out.
This was England's highest successful fourth-innings chase and the tenth highest in Test history.
A remarkable victory, which arguably surpassed their 1981 Ashes Test triumph at Headingley when they beat Australia after following-on -- saw England level the five-match series at 1-1.
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 362-9 (B Stokes 135 no, J Root 77, J Denly 50; J Hazlewood 4-85) Result: England won by one wicket Series: Five-match series level at 1-1.