The 81-minute win meant that Federer avoided the embarrassment of losing two straight group matches in a row for the first time at the year-end event after the six-time champion was beaten by Novak Djokovic in his opening match.
Federer still needed six match points to get the job done in an afternoon of 29 winners and 30 unforced errors, as he broke Gasquet in a marathon final game.
The 17-time Grand Slam winner wasted his first five match points with unforced errors before Gasquet put a return wide.
"Today was just a battle for myself, making sure I move the right way," said Federer.
"I play the right way, I have the right shot selection," the Basel native said.
"Richard does a good job of making you feel uncomfortable; he uses heights, spins really well," he said.
"He likes extended rallies.
"But I guess those are the kind of matches I need right now -- straight sets against a good player.
"It clearly comes at the right time."
Federer, playing the season finale for the 12th consecutive year, earned his 11th win over the Frenchman from 13 matches.
He has now won a record 43 matches at season wrap-up tournaments.
Gasquet dropped to 1-4 at the finals on his second appearance.
Federer will fight for his spot against del Potro, whom he beat in Paris last weekend.
"That win was big for me, he did beat me three times indoors straight, the Basel finals twice, and also here last year," said the Swiss.
"My confidence is higher, and that's what I need to beat the best, and Juan Martin is part of that group honestly."
Federer was momentarily rocked at the start, as Gasquet won the first six points before the Swiss gathered his resources in the must-win contest.
The 32-year-old came from 0-30 in the second game to hold and then seized a break for 2-1.
Federer lost his lead in the eighth game as he saved one break point but sent a backhand wide to bring Gasquet level at 4-4.
The Swiss broke straight back for 5-4 and set up three set points a game later with his third ace.
The longtime London crowd favourite converted on his first to take the early lead after 34 minutes.
Federer began the second set with a break and stayed in charge throughout despite struggling with his consistency before closing out victory.
The win was his 44th of the season.