Bojan Miovski came off the bench to break the deadlock in stoppage time - and spark wild scenes of celebration - as Rangers leapfrogged visitors St Mirren into second place in the Scottish Premiership.
Just as it looked like the Paisley side would leave the home fans frustrated after controlling the second half, substitute striker Miovski pounced on a Ryan Naderi flick to chip goalkeeper Jacob Chapman.
St Mirren were thrashed 5-1 as the holders were dumped out of the League Cup on their last visit to Ibrox nearly a month ago.
As they did then, Derek McInnes' side threatened to blow away the visitors in the early stages. Chapman produced a string of fine saves to deny Naderi, Nicolas Raskin, Djeidi Gassama, Kevin Kelsy and even team-mate Calvin Ramsay.
As against Celtic on Saturday, St Mirren were a constant threat on the break, though, with Rangers centre-back Emmanuel Fernandez fortunate not to concede a spot-kick for a late challenge, while Ramsay passed up two good chances.
The visitors had settled as Rangers appeared to run out of ideas, their 13 goal attempts and eight corners failing to bring a breakthrough before half-time.
St Mirren survived, gradually started to exert control after the break, and Fraser Taylor should have given them the lead when put through one-on-one with Ivor Pandur, only to fire straight at the goalkeeper, before Miovski snatched the points.