In an enthralling match Rangers just out-staged Hearts and with Celtic dropping points at Dundee, the victory put the Gers in top spot for the first time this season.
Hearts drew first blood from the penalty spot via Paul Hartley and it took an own goal by Jamie McAllister to level things just before half-time.
Nacho Novo put Rangers ahead early in the second half only for Mark De Vries to equalise for the visitors. However it was man of the match Novo who sealed the points for the Ibrox side with a late header.
It was a cruel blow for Hearts who had put so much into the game, only to come away empty-handed.
Rangers should have gone ahead in the opening minutes. Fernando Ricksen threaded a superb pass through to Peter Lovenkrands and his cross to the back post was swept wide by Dado Prso when it looked as though he had to score.
Novo tested Craig Gordon in the Hearts goal with a drive before the visitors took the lead.
Andy Webster's powerful headed clearance found De Vries on the wrong side of Jean-Alain Boumsong and though the defender tried not to foul the striker, his tackle from behind was adjudged a penalty.
Boumsong was only booked for his foul and Hartley bulleted his spot-kick past Stefan Klos.
Alex Rae was trying to drive Rangers forward and his crunching tackle ended with Novo volleying wide. Hartley and Dennis Wyness were booked as Rangers stepped up the pressure.
Novo dribbled past Ramon Pereira and McAllister wide on the right but Prso failed to find the target with his header.
The home side equalised just before half time. From Novo's cross Lovenkrands did well to steer the ball across goal and McAllister could only turn it into his own net.
Novo put Rangers ahead early in the second half when he latched on to Zurab Khizanishvili's superb throughball before lofting his shot over the advancing Gordon.
If Rangers thought they had done enough, they were soon brought back to earth when De Vries stepped between a hesitant Klos and Marvin Andrews to prod the ball home from close range.
Indeed De Vries wasted a great chance to put Hearts ahead when McAllister's cross found him unmarked, but the striker headed over.
Gordon pulled off a superb save to deny Andrews' header before Rangers scored the winner.
From Prso's pass, substitute Stephen Hughes did well to cross from the by-line leaving Novo to pick his spot with a firm header.