Old Firm rivals Celtic were threatening to disappear over the horizon as the Light Blues again struggled to breakdown a stubborn defence.
But George Edmundson – back in the starting line-up for the first time since October – slammed home his first goal since joining from Oldham in the summer to level just before half-time.
However, it appeared Rangers – who had dropped five points in their first four games after the winter break – were set to lose further ground on Neil Lennon's champions as the Leith side clung on.
But with just six minutes left, on-loan Genk star Hagi opened his Ibrox account to ensure the deficit stays at seven points with a game in hand. Hibernian, meanwhile, clung onto their slot in the top six.
Ibrox has been an anxious place since the turn of the year with Gerrard's team a shadow of the side that lit a fire under the title race with their win at Celtic Park.
An early goal would have settled the nerves but Alfredo Morelos was foiled three minutes in as he raced beyond Hanlon onto fit-again skipper James Tavernier's pass, with Ofir Marciano making a good save.
This was the fifth game to be staged at Ibrox in the last two-and-a-half weeks and the pitch was starting to suffer. The last thing the home players needed with their confidence levels on the floor were quagmire conditions forcing them to second guess their first touch.
But there was little understanding from the Light Blues' faithful, who responded to every stray pass and over-hit cross with a roar of frustration.
And the groans almost went off the scale on 35 minutes as Hibs opened the scoring.
Edmundson gave away a free-kick as he lunged in on Steven Whittaker. Christian Doidge was first up to meet Allan's delivery but Allan McGregor got nowhere near the striker's looping header, allowing Hanlon to slam into the empty net.
However, the goal sparked Gers into life.
There were unsuccessful claims for a penalty as Ryan Kent tumbled into Whittaker's legs while Scott Arfield wasted a golden chance after being teed up by Joe Aribo.
But scores were level by the break as Edmundson pounced in first-half stoppage time. Tavernier's set-piece delivery from the right ended up pin-balling off the shins of Paul McGinn and Stephane Omeonga before breaking to the Gers centre-back to lash home.
The equaliser immediately changed the mood around Ibrox. The fans roared their team out after the turnaround and were almost celebrating as Hagi and Morelos came close.
Aribo hooked over from close range at a corner while Marciano made another vital block from Morelos as the Hibs box came under siege.
With the clock ticking down and no breakthrough, another bout of angst began to spread through the Gers support.
But Hagi swept the worries away. Connor Goldson nudged an Arfield header on to the Romanian in the box and from a tight angle he arrowed a sublime finish into the bottom corner to send Ibrox wild.