At lunch on the final day, the tourists were 332 for six as they battled desperately to keep their Ashes hopes alive.
Stokes was 117 not out and Tim Bresnan was on seven with England needing a further 172 runs for victory with four wickets in hand.
Set a seemingly impregnable 504 to win, which would be a record in Test cricket, England resumed at 251-5 and appeared to have little hope on a pitch featuring massive cracks that have caused the ball to jag alarmingly off the pitch.
The 22-year-old was temporarily denied a century when he drove Mitchell Johnson straight and the ball deflected off the bowler's hand into umpire Marais Erasmus, costing him the two runs he needed to reach the milestone.
More From This Section
But he got a top edge to fine leg for a boundary from the next ball to notch his first Test hundred and England's first ton of the series.
Not for the first time in the series, it was Johnson that delivered a dagger to English hearts by removing Prior in his third over with the second new ball.
Johnson, who sent a brief scare through the Australian camp when he fell awkwardly while trying to stop the ball on the boundary just minutes earlier, ended a 76-run partnership with Stokes.
Prior had been batting with dogged determination, but rashly chased a wide one and got an edge through to wicketkeeper Brad Haddin to end his 111-minute vigil at the crease.