Federer conceded a set for the first time in five matches against the 48th-ranked Istomin, and rallied from 0-40 down in his first service game in the third.
The seventh-ranked Federer converted his first match point with an angled backhand volley. He's looking for a strong finish to the most difficult season of his career.
Federer's struggles with back injuries and unheralded opponents since March have meant he hasn't secured a place in the eight-man London final next month.
Gasquet's defeat, after Stanislas Wawrinka's first-round exit Tuesday, strengthened Federer's hold on the sixth qualifying position.
Still, home fans were silenced when Istomin broke Federer's serve in the fifth game before serving out the set.
Federer needed a single break, in the sixth game, to even the match. He also asked the chair umpire to reject balls he thought were too soft for play.
In the first game of the deciding set, Federer let two break point chances slip as Istomin avoided trouble with big serves. Federer saved four break points in next game and held despite an inconsistent forehand.
Federer broke for a 2-1 advantage with a powerful forehand winner approaching the net and reeled off four more games for victory.