David Robertson fired Dundee United into the fourth round of the Scottish Cup with a dramatic injury time strike at Tannadice.
United captain Barry Robson celebrates the opener at Tannadice
Barry Robson hit a free kick opener beyond Tony Bullock after 31 minutes, as the Tangerines began to dominate.
Gary Kenneth headed a second until Richard Brittain offered a lifeline from the penalty spot after Jon Daly fouled Kirk Broadfoot.
John Sutton equalised with nine minutes left before Robertson's late winner.
United chief Craig Levein made four changes following the Taysiders' 5-0 thrashing at Rangers on Saturday.
Lee Mair and Barry Robson returned from suspension, while Alan Archibald and Keith Watson came into the home defence which conceded 10 goals in their last two matches.
Simon Lappin, Andy Millen and Ian Maxwell all returned to start for Saints, with Alan Reid and David McKenna moving to the bench, as Gus MacPherson's squad embarked on their first game since since a 2-1 defeat to Inverness on New Year's Day.
The early stages were rather lacklustre, but the visitors thought they had broken the deadlock through their first serious attack.
Mark Corcoran's 12th-minute cross was powerfully headed into the net by John Sutton only for the big striker to be ruled offside.
United responded with Collin Samuel sending an 18 yard half-volley just wide as Levein's men gradually inched their way into the contest.
David Robertson came even closer to scoring in the 22nd minute but his low effort was smothered on the goal-line by St Mirren goalkeeper Tony Bullock at his near post.
However, the Tangerines did go in front with Robson's well-taken set-piece, his eighth goal of the season.
The midfielder tried his luck with a speculative, swerving 25-yard effort, and Bullock was slow to react as the ball went beyond him high into the net.
United got the perfect start to the second half by doubling their lead, with St Mirren still trying to properly organise themselves.
Kenneth rose above the static Saints rearguard to bullet a fine six-yard header home from an inswinging Craig Conway corner, giving the Taysiders some valuable breathing space.
But Saints took advantage of United's complacency to drag themselves back into the game when referee Charlie Richmond awarded a penalty against Daly for a clumsy challenge on defender Broadfoot.
Brittain converted the spot kick to fire fresh life into the contest, and St Mirren's confidence rose sharply as a result.
Levien tried to instill some composure into his players from the touchline, but it was to no avail as the Paisley side grabbed the equaliser.
After 81 minutes Sutton hit a lovely curling effort beyond the advancing Derek Stillie, as United looked increasingly out of sorts.
However, deep into stoppage time, Robertson drove home a well-placed shot with the last kick of the game.
The midfielder's incredible intervention cruelly denied the Buddies a replay, with United now looking forward to an encounter at Inverness Caledonian Thistle.
Dundee Utd: Stillie, Watson (McCracken 85), Mair, Kenneth, Archibald, Conway, Kerr, Robertson, Robson (Duff 59), Samuel, Daly. Subs Not Used: McLean, Hunt, Goodwillie.
Goals: Robson 31, Kenneth 46, Robertson 90.
St Mirren: Bullock, Broadfoot, Millen (Kean 56), Maxwell, van Zanten, Brittain, Potter, Brady, Lappin (Reid 71), Sutton, Corcoran. Subs Not Used: Smith, Mackay, McKenna.
Goals: Brittain 76 pen, Sutton 81.
Ref: C Richmond