The goals arrived late in each half, with Smith netting the opener just before the break while debutant Gallagher added a second with 92 minutes on the clock.
However, the Pars will feel aggrieved that they failed to take any points from a match they dominated for long periods and were also forced to play the final 12 minutes with just 10 men following the dismissal of Danny Grainger.
Smith broke the deadlock with his first goal in over seven years, curling home a 25-yard free-kick in the fourth minute of first-half injury time.
The defender, whose only other Rangers goal had come against the same opposition in November 2006, located the top right-hand corner of the net and well out of reach of substitute keeper Ryan Goodfellow.
Goodfellow had been called into action inside five minutes after Ryan Scully was forced off the pitch with a dislocated toe.
Smith's goal had come against the run of play, the visitors having been the more adventurous side during the majority of the first half.
Ross Forbes, with a free-kick just outside the box, and Lawrence Shankland - who hooked wide from 12 yards - should have done better for Pars before the break, while Rangers midfielder Fraser Aird curled a fierce low shot inches wide of the left post early in the game.
The second half was largely uneventful, with both sides generally restricted to long-range efforts.
One such strike, from Dunfermline's Stephen Husband on 72, was poorly struck from 25 yards and easily gathered by home keeper Cammy Bell in a passage of play which seemed to sum up much of the match.
Six minutes later the visitors lost Grainger, who collected two yellow cards, the second of these for slicing down a sprinting Gallagher.
And, as the more enterprising Dunfermline chased a late equaliser, the hosts broke clear in the second minute of injury to seal the win.
Following a strong run by Black, the ball fell into the path of Gallagher who stroked it home confidently from 18 yards.
Rangers, who clinched the League One title in midweek, are now 29 points clear of second placed Pars having won 27 of their 29 games this campaign.