Stockport beat Barnsley to seal a third-placed finish and set up a League One play-off semi-final with Stevenage.
Adama Sidibeh's first-half goal for County was cancelled out by Adam Phillips before Oliver Norwood scored from the penalty spot after the break to restore the lead.
And Benony Andresson sealed the points for Stockport in second-half stoppage-time.
County took a deserved lead in the 23rd minute after Barnsley goalkeeper Kieren Flavell let a Norwood cross slip through his fingers, with the ball falling straight to the feet of Sidibeh, who fired home.
After Corey Addai had made a wonder save to deny Phillips from close range, Corey O'Keeffe crossed the ball back into the box for the midfielder, who levelled in the 53rd minute.
Norwood converted from the spot - with less than 20 minutes remaining - to put County back in front after O'Connell was adjudged to have brought down Josh Stokes.
Andresson sealed the three points in the ninth minute of added time, calmly slotting the ball past Flavell to send the away end wild and set up a play-off semi-final against Stevenage.
Match report supplied by PA Media.
Hourihane: 'Very emotional'
Challinor: 'Third is great... but we've been here before'