When Light Blues defender Carlos Bocanegra shot the home side into the lead in the 55th minute it looked like they would go and make the result more comfortable.
However, the Highlanders fought back ferociously and former Rangers midfielder Andrew Shinnie, on as substitute for Greg Tansey, levelled before they missed several good chances to grab an unlikely win.
They were made to pay in the cruellest fashion when Lafferty, on for Alejandro Bedoya early in the second half, struck with eight minutes remaining to ease the nerves and increase the gap over their Old Firm rivals who play at St Johnstone tomorrow.
Rangers have been unconvincing in recent weeks and their fans will have left Ibrox aware that they were let off the hook.
Bedoya and defender Sasa Papac came into the Rangers side at the expense of Dorin Goian, who failed to recover from a fever and Lee McCulloch, who started on the bench along with striker Lafferty who returned from a back injury.
Caley boss Terry Butcher made three changes with Lee Cox, Gregory Tade and Graeme Shinnie coming in for injured Chris Hogg, suspended David Davis and Andrew Shinnie, who was named substitute.
The Highlanders took the spoils in the first half with an impressive display.
It was a slow, unconvincing start by the home side and in the third minute Caley midfielder Cox stole into the Rangers box but failed to catch his shot properly, the ball spinning harmlessly wide.
Inverness midfielder Tansey then had a shot blocked by Ibrox defender Kyle Bartley.
In the 10th minute the Light Blues threatened for the first time and Caley keeper Ryan Esson made a terrific save to deny defender Steven Whittaker, who met a Gregg Wylde cross from eight yards out to power a header down towards the bottom corner.
There was not a great deal of creativity from the Ibrox men which began to irk the home support as they surveyed another possible afternoon of frustration.
The home side’s corner count slowly mounted, though and in the 28th minute top scorer Nikica Jelavic headed Wylde’s corner from the right over the bar but still the Highlanders refused to be cowed.
After Papac was robbed by Tansey, Cox went down the right and drove the ball across the box and the home fans were glad to see Bartley clear the danger.
In the 36th minute there was a strong Caley appeal for a penalty when Richie Foran’s header looked like it might have struck the arm of Jelavic in the Rangers box but referee Bobby Madden was unimpressed.
Jelavic had to stretch at the back post to reach a searching Wylde cross from the left but the ball fell into the arms of Esson.
McCulloch replaced Maurice Edu for the start of the second half and within three minutes Bedoya and Jelavic got into a tangle as they attacked a Lee Wallace cross and the chance was gone.
Caley striker William McKay claimed he was held by Bartley as he turned the Rangers defender inside the penalty box but again referee Madden shook his head, leaving McKay in a rage as Gers keeper Allan McGregor picked up the loose ball.
Lafferty came on for the injured Bedoya in the 52nd minute and the home side stepped up the pace which brought its reward three minutes later.
When Wallace crossed into the box Jelavic chested down for defender Bocanegra to slam the ball in from close range.
On the hour mark Lafferty escaped the attention of the Caley defence to go through on Esson but the Northern Ireland international slipped his side-footed shot past the far post.
The champions were in total control and in the 63rd minute Papac sent a spectacular drive from 30 yards crashing off the Caley bar.
But in the 67th minute there was a shock for the home side when Tade raced down the left and cut the ball back for substitute Andrew Shinnie and the former Rangers player side-footed the ball past McGregor from eight yards.
The Ibrox fans booed because Jelavic was down injured after a tackle by Roman Golobart in the lead-up to the leveller.
In the 70th minute Foran had the ball in the net from an Andrew Shinnie free-kick but the flag was up for offside.
In the 77th minute McKay rounded McGregor and from an acute angle struck the post.
Caley’s Jonny Hayes went round McGregor and had a close-range shot cleared off the line by Wallace, before McGregor had to save from McKay with the home defence in disarray.
But in the 82nd minute, and against the run of play, Lafferty ran onto a Steven Davis pass and knocked the ball past Esson.