Rangers eventually secured the victory which at least means Celtic have to beat Kilmarnock on Sunday to secure the League title.
The home team fell behind to well-taken goal by Andrius Velicka but a powerful Gavin Rae header early in the second half drew Rangers level.
It was inspirational skipper Barry Ferguson who scored the winner with a marvellous hooked volley 11 minutes from time.
Rangers started well and Dado Prso dispossessed Marius Zaliukas before keeper Craig Gordon rescued his side with a good save.
Hearts took the lead when Laryea Kingston broke swiftly from midfield before cleverly releasing Velicka who struck a firm shot into the far corner of the net.
Gordon produced an outstanding save to keep Sasa Papac's header out, although, unfortunately, the defender was then stretchered off after a clash of heads with Christophe Berra.
Rangers equalised after a flowing move down the right ended with Alan Hutton intelligently cutting the ball back to Rae who powered an unstoppable header home from ten yards.
This goal took the pressure off Rangers and Brahim Hemdani's free-kick beat Hearts' offside trap only for Hutton to waste the chance.
Rangers' winner was well worth waiting for. Prso made progress down the left and his cross was only cleared as far as Hemdani.
The midfielder's header back into the penalty area was controlled by Ferguson before he hooked a shot into the top corner.
The victory keeps Rangers well on course for second place and a chance to qualify for the Champions League.