A last-gasp Marcus Fraser goal saw St Mirren come from behind to make it through to the quarter-final of the Scottish Cup.
After a goalless first-half, the Buddies fell behind early after the interval when Nikolay Todorov slammed home the opener. But Kristian Dennis, on his first start since his return from injury, levelled two minutes later before Fraser knocked in the winner in the final minute of normal time. Saints will face the winners of Kilmarnock and Montrose with the two sides meeting tomorrow at Rugby Park.
It was a real cup tie from start to finish with both sides having numerous chances throughout the 90 minutes. Ilkay Durmus sent a scissor kick over from the edge of the area in the opening moments, while Jamie McGrath flashed wide on 12 minutes.
A minute later Jak Alnwick made two good stops in the space of a minute to keep Todorov and Daniel Mackay from opening the scoring. The goalkeeper was down low to deny the former before getting a hand to the latter's strike.
On 17 minutes it was opposition goalkeeper Mark Ridgers who was made to work as he saved from Dennis. Dennis was inches away from the first goal on the half-hour mark when he got on the end of a terrific cross-field pass from Kyle McAllister. The striker did well to fashion space before his shot was deflected just wide.
Alnwick made another two big saves to keep the visitors at bay. He did well to push away Todorov's effort on 33 minutes and then got a fingertip to Scott Allan's hit from 20 yards to touch it on to the post.
Saints were forced into a change a few minutes before the half-time interval. Jake Doyle-Hayes couldn't shake off a knock he had picked up minutes earlier and was replaced by Richard Tait.
With a minute of the half remaining, Dennis did brilliantly well to bring the ball down in a tight space of the box to get a shot away. It was deflected onto the cross bar before falling into the welcoming arms of Ridgers.
There was an early warning sign at the start of the second-half with Alnwick getting strong hands to turn behind Mackay's strike. From the resulting corner the visitors would take the lead. Todorov was given all the space in the world to slam home from close range to put the Championship side ahead.
But Saints hit back instantly with Dennis levelling within two minutes. The forward smashed into the far corner from just inside the box to net his fifth St Mirren goal and his second in the Scottish Cup this season.
The Buddies could have been ahead a little over 10 minutes later with the woodwork denying Durmus and Dennis. The Turkish winger cracked the bar with a curling drive before Dennis smacked the post from the rebound.
The tie could have gone either way with both sides continuing to create. It looked like Allan had given Caley Thistle the lead again with less than 20 minutes remaining when he raced on to a lovely through ball from Miley Storey. The on-loan Hibernian midfielder's strike slid just centimetres by Alnwick's far post.
Saints were denied by the woodwork for a fourth time with five minutes remaining as Durmus got his head on the end of a Fraser cross. It cracked off the post with Ridgers gathering despite not knowing too much about it.
And then, into the final minute of normal time, St Mirren found the winner. Again it looked like the woodwork would stop the Buddies after nifty footwork from Jon Obika saw the striker fire into the post. The ball fell back to substitute Brandon Mason who sent the ball across the face of goal to Fraser who rolled home from close-range to make sure Jim Goodwin's men were the first side to qualify for the last eight.
Full-Time: St Mirren 2-1 Inverness Caledonian Thistle
St Mirren: Alnwick, Fraser, McCarthy, Shaughnessy (c), Connolly, McGrath, Doyle-Hayes (Tait 41), McAllister (MacPherson 46), Durmus, Dennis (Mason 75), Obika
Subs Not Used: Lyness, Finlayson, Reid, Henderson, Erwin
Inverness: Ridgers, Welsh (Lyall 90), Devine, Deas, Carson, Storey, Allardice, McKay, Allan, D. Mackay, Todorov (Sutherland 87)
Subs Not Used: C.Mackay, McHattie, Doran, MacGregor, Vincent, Harper
Referee: John Beaton
Assistant Referee: Sean Carr
Assistant Referee: Craig Ferguson
Fourth Official: Craig Napier