Goals from Alun Armstrong and Louis Cavaco had seemingly guaranteed the Second Division side a place in the last four of the Coca-Cola Cup, only for Egil Ostenstad to get an equaliser with five minutes remaining.
Now with home advantage in next Wednesday's replay the Saints should progress to meet Middlesbrough in the semi- finals.
The irony was that the Stockport manager, Dave Jones, had been preaching the fickleness of fate beforehand. "All it takes is a bad week," he said. "And we would be out of everything except the promotion race." The swift transition from despair to hope and then to despair again underlined his message.
Southampton had clearly come primed to absorb early home pressure and the tide seemed to be moving in their direction when they took the lead after 16 minutes. Simon Charlton sent a long pass down the left to Ostenstad, who outpaced Mike Flynn with ridiculous ease before side-footing past Paul Jones in the County goal.
The script appeared to be set in stone. Southampton could afford to sit back and raid on the break as County charged into an ambush. Appearances proved deceptive, however, and the match swung with two goals in a minute.
First the Southampton defence went missing as Brett Angell was allowed to chest Lee Todd's 26th minute free-kick and then pass to Armstrong. The Stockport striker, surprisingly, was on his own from 12 yards out and he shot into the far corner with his right foot.
The next arrived almost straight from the kick-off. Stockport won possession and the ball was played to Chris Marsden on the left. His cross was slightly ahead of Cavaco, but the Portuguese winger dived to head the ball into the net via a post.
Southampton introduced Eyal Berkovitch at half-time to pep up the attack, but it took the Israeli a long, long time to make an impact. Indeed, Stockport dictated the tempo in the early stages of the second half until Ulrich van Gobbel's header against the bar after 69 minutes announced a sea change.
Even so the Stockport goal appeared to be having a charmed life until Berkovitch wriggled into the area in the 86th minute. His pass to Ostenstad did not appear decisive but the Norwegian turned sharply and got just enough of a touch with a shot for the ball to crawl across the line.
County looked bewildered and almost went out of the competition in the last minute. Matthew Le Tissier waited an age 15 yards out, beat Jones with a lovely chip but, Mike Flynn appeared on the line to head clear.
Stockport County (4-4-2) Jones; Connelly, Flynn, Gannon, Todd; Durkan, Bennett, Marsden, Cavaco; Angell, Armstrong. Substitutes not used: Mutch, Edwards (gk), Dinning.
Southampton (3-5-1-1): Beasant; Van Gobbel, Monkou, Maddison (Lundekvam, 59); Oakley, Neilson, Magilton, Hughes (Berkovitch, h-t), Charlton (Slater, 66); Le Tissier; Ostenstad.
Referee: R Poulain (Huddersfield).