Steven Gerrard watched another chance to claim his first trophy as Rangers boss slip through his fingers as Conor McCarthy’s stoppage-time winner saw St Mirren smash the Ibrox side’s 27-game unbeaten record.
Gers looked on course for a place in the Betfred Cup semi-finals after Connor Goldson fired them ahead early.
The Paisley men hit back with Jamie McGrath’s double before Steven Davis thought he had forced extra-time with his late strike.
But there was still time defender McCarthy to pop up with the precious goal which handed Jim Goodwin’s team a sensational shock 3-2 win at the SMISA Stadium.
Rangers have looked imperious this year and their fans fully expected their team to march all the way to Hampden to lift their first trophy in a decade after seeing bitter rivals Celtic exit the competition in the last 16.
But instead it is Saints who are heading back to the national stadium for the first time since lifting the League Cup back in 2013 after becoming the first Scottish side in nine months to topple the Premiership leaders.
There was a brief delay to kick-off after referee Andrew Dallas pulled up in the warm-up, with fourth official David Dickinson taking over.
But Rangers were eager to make up for lost time and grabbed the opener inside seven minutes.
Joe Aribo released Scott Arfield in the box but the Buddies could only clear his cross to Goldson, who strode forward purposely before drilling past former Rangers goalkeeper Jak Alnwick.
Bongani Zungu took a sore one when Ethan Erahon planted his studs into the South African’s ankle but Dickinson decided it was only worthy of a yellow.
Gerrard had made another four changes to his side after Sunday’s win at Dundee United but there was a disjointed look about them. Goodwin did brilliantly to nullify 17-goal James Tavernier’s threat as Gers rampaging full-back was marked out the game.
Calvin Bassey sat deeper than Borna Barisic normally does at left-back and Zungu yet to find his rhythm in midfield. Cedric Itten, starting in place of Alfredo Morelos after the Colombian was ruled out for his elbow on Dundee United’s Mark Connolly, also found it hard to involve himself in a quiet first 30 minutes.
The big Swiss hitman did get a header on target from a Tavernier corner as Rangers eventually created their only other clear-cut chance of the first half 10 minutes before the break but McGrath was well-placed on the line to clear.
And from almost going 2-0 down, Saints found themselves level after 40 minutes.
Bassey had not looked comfortable in his early dealings with Dylan Connolly and got caught wrong side again as he barged the Irishman over to hand Dickinson the easiest of decisions to award the spot-kick, tucked away coolly down the middle by McGrath.
Rangers lived dangerously at the start of the second period too as Connolly’s cross drifted over Allan McGregor’s head before coming back off the crossbar.
It was a warning Gerrard’s team failed to heed and they found themselves behind to Scottish opposition for only the second time this season in the 53rd minute.
Saints pounced on Leon Balogun’s loose pass, releasing Connolly down the right. His cross was set back by Jon Obika for McGrath, who again refused to panic at the big moment as he shifted the ball onto his left foot before beating McGregor again.
Gerrard responded by replacing Bassey and Arfield with Barisic and Davis but Ryan Kent’s attempt to con his side a penalty was spotted by Dickinson, who booked the Rangers winger for diving as he threw himself to the floor after going past Marcus Fraser.
Tavernier thought he had levelled after 65 minutes but Kemar Roofe had let the ball run out of play before crossing.
It was a full Rangers cavalry charge as the game entered the final 20 minutes. Goldson nodded wide with a free header as time appeared to be running out.
But with two minutes left, Davis thought he had rescued Gers, driving the ball into the ground and over Alnwick’s despairing reach after Tavernier’s free-kick had thudded against the post.
To St Mirren’s credit, they did not give up hope and immediately raced upfield to force a string of corners. McGregor did brilliantly to keep out a Richard Tait header but was helpless as McCarthy rammed home the winner from close range.
Goodwin lost his cool in the celebrations and was sent off for an inflammatory gesture but he was back on the field at full-time to celebrate with his jubilant players.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.