An extraordinary goal by Marc Goodfellow two minutes from time settled this FA Cup second round replay in Swansea City's favour just as it looked as though extra-time was on the cards.
Stockport County keeper Neil Cutler, who spent three months on loan at the Vetch Field two seasons ago, sent a clearance kick straight to Goodfellow 30 yards out.
The Bristol City loan player struck the ball first time and hit the back of the empty net with Cutler still way out of his goal.
After a dire first half the Swans began the second period in more forceful fashion and they only took 90 seconds to open the scoring.
Adrian Forbes threaded a neat pass through to Paul Connor and the former Rochdale striker beat the offside trap, shrugged off a couple of half-hearted tackles, and slotted the ball into the corner of the Hatters net.
The goal settled the home side's nerves and Forbes had a chance of doubling the lead after cutting in from the right, but his goalbound shot was blocked by the visitors' defence.
The Hatters brought on veteran striker Stuart Barlow in the 65th minute and he immediately caused problems for the home defence.
In the 72nd minute following a rare Stockport corner the ball was cleared by the Swans defence, but it went straight to Hatters skipper Danny Griffin who was completely unmarked 35 yards out from goal.
He connected superbly and his shot flashed into the home net with keeper Willy Gueret helpless.
Goodfellow was brought on in the 78th minute to provide a little craft down the wing and it proved to be an inspired substitution when he struck home the late winner.
Kenny Jackett's now visit Championship side Reading at the Madejski Stadium in round three.