Rangers maintained their challenge for a Champions League place after Sotirios Kyrgiakos ended a defiant, rearguard display by Dunfermline Athletic.
Peter Lovenkrands set up Sotirios Kyrgiakos' winner
Pars goalkeeper Bryn Halliwell denied the Glasgow side with a string of fine saves, while Dado Prso sent an early effort against the post.
Stefan Klos saved well after Gary Mason threatened briefly at the other end.
And Kyrgiakos headed home a cross from substitute Peter Lovenkrands before Klos superbly denied Andy Tod late on.
Lovenkrands had been dropped to the bench along with Ian Murray, with Kris Boyd and defender Steven Smith returning to Rangers' starting line-up.
But the surprise was the return of Klos, making his first start since the 2-0 defeat by Celtic in the CIS Insurance Cup in November in place of ill regular goalkeeper Ronald Waterreus.
The German was rarely threatened, the traffic heading towards Halliwell, who had returned in place of Allan McGregor, the on-loan goalkeeper being barred from playing against his own club.
A five-man defence signalled Dunfermline's intention to frustrate Rangers.
And, following a brief goalmouth scramble, Boyd headed a Prso overhead kick against the leg of Halliwell from close range.
Top scorer Boyd headed a Thomas Buffel cross over and the striker also missed on the rebound after a 25-yard drive from Prso thundered off the post.
Barry Ferguson then stumbled before hammering a shot against Halliwell from eight yards.
It was Halliwell to the rescue again when he got a fingertip to a powerful Chris Burke volley from distance.
Alan Hutton set up Buffel 10 yards out, but the Belgian's shot was blocked clear.
Dunfermline almost took a surprise lead immediately after the break.
A clever Lee Makel flick put Mason clear, but Klos rushed off his line to block the midfielder's effort clear.
However, Rangers were soon back on the attack and Ferguson sent a drive a couple of yards over.
Halliwell, who had conceded eight in his previous two games against Rangers, next denied Buffel as the Belgian's drive was heading for the top corner.
When Halliwell was beaten by a Burke effort, substutite Jamie McCunnie, on for the injured Makel, cleared off the goalline.
But Kyrgiakos eventually broke the deadlock when the Greek defender headed home a cross from Lovenkrands after 70 minutes.
However, they had Klos to thank for the victory when he touched over a superb, 16-yard volley from Tod in the dying seconds.
Rangers: Klos, Hutton, Rodriguez, Kyrgiakos, Smith, Burke (Novo 85), Hemdani, Ferguson, Buffel (Lovenkrands 68), Prso, Kris Boyd.
Subs Not Used: Gallacher, Andrews, Gavin Rae, Murray, N'Guessan.
Goal: Kyrgiakos 70.
Dunfermline: Halliwell, Labonte, Tod, Scott Wilson, Thomson, Shields, Ross (Tarachulski 84), Mason, Makel (McCunnie 58), Muirhead (Daquin 75), Donnelly.
Subs Not Used: Shaw, Andy Campbell, Iain Campbell, Phinn.
Booked: Scott Wilson.
Ref: B Winter