Anthony Elding's 74th minute strike and Anthony Pilkington's stoppage-time goal separated the sides as Dons missed a succession of chances.
It ends their eight-game winning streak and was County's first win in five.
Stockport should have taken the lead within minutes of the start. Elding played Leslie Thompson through but the midfielder scuffed his shot wide of goal.
In the tenth minute the Dons had a glorious chance of their own. Aaron Wilbraham turned his man with ease, but blasted his shot straight at Conrad Logan when through on goal.
The game quietened down after that and it took the Dons until the 23rd minute to register their next shot on target, Lloyd Dyer cutting in well and blasting a left-foot shot that was well-saved by Logan. Moments later Leon Knight fizzed a shot past the post from 25 yards.
Wilbraham had another great chance on 35 minutes after Knight put him through on goal, but he tried to round Logan and was forced too wide of goal, his pass back into the box being easily cleared by the defenders.
Just two minutes into the second half Wilbraham had another great chance to open the scoring but his header hit the post and bounced out.
The Dons thought they'd taken the lead on 61 minutes when Drissa Diallo tapped home from point-blank range, but the goal was ruled out for a foul in the build-up.
This seemed to rally the Dons and Dyer forced another good save from Logan after Knight had picked him out superbly, but his shot was just too close to the keeper, who beat it out well.
Then from nowhere Stockport took the lead on 74 minutes. The ball fell kindly to Elding, who had been recalled to the side after a club suspension, just inside the penalty area, and the striker finished well.
The Dons came back but Wilbraham must have known it wasn't his day when he missed another sitter. The ball fell to him in the box, but he shot straight at Logan.
Jemal Johnson then went through on goal but his shot was tipped wide by Logan.
To rub salt in the wounds Stockport scored another in stoppage time, Pilkington tapping in from close range.