Keith Andrews' 74th minute winner meant MK Dons' promotion to League One was finally confirmed.
He fired home from 20 yards as the Dons were forced to twice come from behind.
A cracking Edgeley Park atmosphere greeted the players on a windswept afternoon, and it was the hosts who created the first chance.
Tommy Rowe curled in a corner-kick from the right, but Dominic Blizzard headed wide from eight yards.
The hosts again went close on 23 minutes after a neat move through the middle.
Anthony Pilkington played in Liam Dickinson, but the big striker could only fire into the side-netting from an extremely acute angle.
Dickinson made no mistake six minutes later though. He profited from a poor clearing header by Danny Swailes as he nipped in before tucking the ball low under the body of Willy Gueret from 10 yards.
The home fans went wild, but the Dons produced a perfect riposte less than a minute later.
Skipper Andrews rolled the ball neatly to Mark Wright and he curled home a great shot past John Ruddy from the edge of the Stockport box.
The Dons had a mighty scare just after the restart when Jude Stirling almost sliced a Shaleum Logan free-kick into his own goal.
However, it was another quick goal apiece that had all sides of the stadium on their feet again.
On 58 minutes Stockport went in front again when sub Adam Proudlock blasted home from 20 yards with his first touch, but the Dons again hit back within a minute as Alan Navarro followed up his own shot after Ruddy had saved his first effort.