The Gers arrived in Edinburgh four points off the pace and it looked like they might be about to blow the three-way battle for the championship wide open when they led at the break through Dujon Sterling's deflected effort.
But Hearts, having been outplayed for long periods of the first half, regrouped at the break and turned the game around through goals from Stephen Kingsley and Shankland.
The buoyant Jambos – who have won each of their last three games – are now three points ahead of second-placed Celtic with a superior goal difference and a whopping seven clear of Gers, with just three games remaining of this compelling Scottish title race.
Hearts boss Derek McInnes said on Friday he wanted to see Tynecastle "in all its glory" for one of its biggest-ever games, and he certainly got his wish as his team emerged to a sea of maroon and white and a cacophony of noise.
But Rangers built a head of steam and they silenced the home support in the 23rd minute. James Tavernier's long throw into the box was partially cleared by the head of Stuart Findlay, but only as far as Sterling whose volley from eight yards out deflected in off Michael Steinwender.
McInnes responded by sending on Blair Spittal for the start of the second half and the change helped spark the Jambos into life.
The equaliser came in the 54th minute when Alexandros Kyziridis cut in from the right and curled a low shot off the far post, with Kingsley perfectly placed to guide in the rebound from just outside the six-yard box.
Hearts' tails were up and they grabbed the decisive goal in the 71st minute when Spittal released Kingsley down the left and his cutback took a deflection off Tavernier and fell kindly to Shankland, who despatched an emphatic low left-footed finish beyond Jack Butland, sparking delirious scenes.