Mansfield had twice found themselves behind in an exciting first half with Louie Barry on target on six minutes, George Maris levelling on 15 minutes and Fraser Horsfall scoring on 25 minutes.
David Keillor-Dunn also rattled the County crossbar.
But after Ben Hinchcliffe had made two fine saves in succession Stags were finally level again through Keillor-Dunn on 70 minutes who then put Mansfield ahead for the first time nine minutes later.
Stockport were the best team Stags have faced so far, but the home side dug deep and deserved the win in the end.
Less than two hours from kick-off a storm lashed torrential rain down on the town and very quickly the surrounding roads were flooded and the One Call Stadium was badly hit.
Rain ran down the steps in the stand like waterfalls, leaks sprung in rooves and the pitch was drenched.
With the ball unable to bounce on the sodden surface it was decided at 2pm to put kick off back to 3.15.
Despite a couple more showers, staff worked hard and the sun finally came out and the game was able to go ahead.
With nine players now out injured, recent signing George Williams was given a debut at right back in place of injured centre half Baily Cargill while Rhys Oates replaced Will Swan in attack.
Aden Flint captained the side on his 500th career appearance and versatile Jordan Bowery deputised for Cargill in the heart of defence for the injury-hit Stags.
There was good news on Stephen Quinn as he was able to start, despite coming off with a knee injury at Grimsby last weekend.
Defender Lewis Brunt, signed on Thursday on a season-long loan from Leicester City, was named on a youthful bench.
Stockport were first to show on a surface still sodden in patchs and there were shouts for a penalty as Quinn tackled Knoyle in the box on three minutes, but the officials were unimpressed.
But County carved Stags open down the centre for the opening goal on six minutes.
A string of passes down the centre ended with Collar feeding Barry and the Stockport man guiding home a low finish into the bottom left corner from 16 yards with Pym rooted.
Stags responded with Keillor-Dunn laying the ball back from the left by-line and Maris sweeping a low ball across the face of goal.
Maris then tried to find Keillor-Dunn in the middle with a low cross from the left, but Wright slid in to concede the corner just in time.
But Stags were level on 15 minutes. Oates tried to burst into the box on the left but was tackled. The ball ran to Quinn who curled it in low into the danger area and Maris turned it home first time from eight yards out.
Keillor-Dunn had a shot on the turn blocked as the home side pressed hard.
On 24 minutes Pym had to get his legs in the way of Olaofe after he had turned sharply in the box and tried to squeeze the ball in at the near post from a tight angle.
But from the 25th minute corner Stockport were ahead again as Horsfall rose unchallenged at the far post to head home Touray's flag kick.
Mansfield were almost level within four minutes as Keillor-Dunn controlled a Williams cross from the right but crashed his finish off the top of the crossbar and over.
Hinchcliffe was safely behind a low Oates shot from 20 yards on 39 minutes.
On 41 minutes Pym almost gifted Stockport a third as he came out of his box to clear the ball but gave it away to Barry who, with an open net to hit from 35 yards, fired wide.
Wright got a block in on an Akins shot in Stags' first raid after the break.
Macdonald's low shot from long range was then easy for Hinchliffe to gather.
Reed was booked for a trip on Croasdale on 52 minutes.
Macdonald then had to clear a dangerous low cross from Barry after he had reached the left by-line.
On 61 minutes Stags sent on Swan for Williams with Akins dropping to right back.
On 65 minutes good approach play saw Stags get the ball into the box again, but Keillor-Dunn's finish from eight yards lacked power and was an easy save for Hinchclife.
Stags twice came close on 69 minutes as Hinchcliffe produced magnificent saves to deny Keillor-Dunn and then Maris.
But from the corner from the second save Keillor-Dunn took the ball to the right corner of the box and his low shot took a big deflection and rolled into the net past a helpless Hinchcliffe.
Stags flooded forward for a winner and Wright came up with a brilliant last ditch block to deny Maris from close range with the home fans now in full cry.
And the reward for their pressure came on 79 minutes as Quinn's perfect pass to Keillor-Dunn on the left of the box saw him curl an inch-perfect finish across the keeper and inside the far post.
Six minutes were added as home nerves jangled, but Stags held tight and Swan even had time to force a great save from Hinchcliffe who got his legs in the way in a on-on-one.
STAGS: Pym, Bowery, Flint, Williams (Swan 61), Macdonald, Reed, Maris (Cooper 90+4), Quinn (Clarke 84), Keillor-Dunn (Brunt 84), Oates, Akins. SUBS NOT USED: Flinders, Wauchope, Abdullah.
STOCKPORT: Hinchcliffe, Knoyle, Touray, Wright, Horsfall (Powell 84), Madden (Rydel 75), Collar (Evans 75), Pye, Croasdale, Barry (Crankshaw 84), Olaofe. SUBS NOT USED: Smith, Mee, Johnson.
REFEREE: Ollie Yates.
ATTENDANCE: 7,433 (969 away).