The series is now tied 1-1 with two more Tests to go.
After being bowled out for just 67 in the first innings, England were up against it, chasing a daunting 359 for victory after Australia put up 246 in the second innings. The visitors were bowled out for 179 in the first innings after England skipper Joe Root put them into bat.
This became the second-highest successfull run chase in Test cricket on English soil and the joint fifth overall.
Down in the dumps several times in their second dig, Stokes who was unbeaten on 84 in the World Cup final on July 14 at Lord's once again remained unconquered on 135 from 219 balls, his innings laced with 11 fours and a whopping eight sixes.
England needed 203 for a win at the start of the day with Stokes batting on 2. Root got out in the first session for 77 and then Jonny Bairstow (36) shared an important 86-run stand with Stokes.
Bairstow was caught by Marnus Labuschagne at second slip off Josh Hazlewood after lunch.
Things fell apart for the hosts after that as Jos Buttler (1) was needlessly run out and Chris Woakes (1) was caught by Mathew Wade at short extra cover to give Hazlewood his fourth wicket.
Stuart Broad was trapped in front by James Pattinson as England were 286/9 with 73 runs still remaining.
What transpired from there on was stuff of legends as Stokes singlehandedly dragged England out of nowhere to a historic triumph, making him one of the finest all-rounders the game has ever produced. Tailender Jack Leach (1 not out) hung on well as they stitched together a series saving unbroken 76-run stand for the last wicket.
Drama reigned supreme towards the end. With two runs to win, Nathan Lyon missed a gilt-edged chance to run Leach out as he could not hold on to the ball.
In the next ball, all the Aussies went up for a big lbw appeal but umpire Chris Gaffaney turned it down, with the tourists having no reviews remaining. Replays showed Stokes was out as the ball pitched on line and was going to hit the stumps.
After playing 17 balls to remain on nought, Leach scampered to a single to open his account and tie the match with the crowd raising the roof.
Stokes then put a perfect end to a mind-boggling thriller, hitting Pat Cummins for a four to complete the miracle.
Earlier, Stokes brought up his eighth and most special Test hundred by hitting Australia's best bowler Hazlewood for a four. He was dropped on 116 by Cummins at third man.
Stokes earlier hit a switch hit off Lyon that landed in the stands in the 119th over to set the tone and bring the equation down to 50 in stunning fashion with every shot being cheered to the rafters.
The fourth Test begins in Manchester on September 4.
Brief scores: Australia 179 and 246 (Marnus Labuschagne 80; Ben Stokes 3/56); England 67 and 362/9 (Ben Stokes 135 not out, Joe Root 77, Joseph Denly 50; Josh Hazlewood 4/85)
( With inputs from IANS )