Kyle McAllister's goal three minutes from time helped 10-man St Mirren come from two goals down to beat Alloa 3-2 in the fourth round of the William Hill Scottish Cup.
The winger, signed on loan from Derby on Friday, curled in a terrific effort from the edge of the penalty box to deny Alloa manager Jim Goodwin a triumphant return to his former club.
Goodwin looked set to savour another famous victory thanks to first-half goals from Alan Trouten and Kevin Cawley, but strikes from Cody Cooke, Ethan Erhahon and then McAllister after the break saw the Ladbrokes Premiership side, who had Brad Lyons sent off in the first half, progress.
All six of St Mirren's January signings were involved in their first game following the winter break. Goalkeeper Vaclav Hladky, defender Mihai Popescu and midfielders Lyons and Greg Tansey all started, while Jordan Holmes and McAllister were on the bench.
Alloa, meanwhile, had to do without Jordan Kirkpatrick due to a gentlemen's agreement following his arrival from St Mirren, while Jack Aitchison, recruited on loan from Celtic, was listed as a replacement.
Alloa, eighth in the Ladbrokes Championship but undefeated in six games prior to this tie, started confidently, with an early low drive from Connor Shields testing Hladky at his near post.
The visitors were looking comfortable and took a deserved lead after 25 minutes. Liam Dick advanced down the left wing before picking out Trouten who supplied a composed finish.
St Mirren's disappointment was compounded just three minutes later when Lyons was shown a second yellow card by referee Don Robertson for simulation following a challenge from Andy Graham. The Northern Irishman had been booked earlier for a foul on the same player.
Alloa sensed an opportunity and doubled their lead after 34 minutes. The ball broke for Cawley outside of the box and the winger unleased a stunning shot that gave the goalkeeper no chance as it arced into the far corner.
St Mirren gave themselves a lifeline after 68 minutes when Cooke bundled in the rebound after Simeon Jackson's shot was saved, before Erhahon drew them level after 85 minutes with his first senior goal.
With the teams heading for a replay, McAllister curled in a spectacular shot after 87 minutes to send St Mirren through.
ga('create', 'UA-72310761-1', 'auto', {'name': 'pacontentapi'});
ga('pacontentapi.set', 'referrer', location.origin);
ga('pacontentapi.set', 'dimension1', 'By Press Association Sport staff');
ga('pacontentapi.set', 'dimension2', '2fc1692d-d57d-47e4-979a-9386bd0d5a2a');
ga('pacontentapi.set', 'dimension3', 'paservice:sport,paservice:sport:club-news,paservice:sport:football,paservice:sport:match-reports');
ga('pacontentapi.set', 'dimension6', 'story');
ga('pacontentapi.set', 'dimension7', 'composite');
ga('pacontentapi.set', 'dimension8', null);
ga('pacontentapi.set', 'dimension9', 'sport:football');
ga('pacontentapi.send', 'pageview', { 'location': location.href, 'page': (location.pathname + location.search + location.hash), 'title': 'Kyle McAllister\u2019s late strike sends St Mirren through'});