The Swiss, playing his first tournament since beating Rafael Nadal to lift a fourth consecutive Wimbledon title, claimed his seventh title this year and the 40th of his career.
Gasquet, one of just four players to beat Federer in the last two years, looked set to pull off an upset as he swept through the opening set.
The world number one, however, showed his pedigree as he hit back to take his second Toronto Masters in three years and extend his winning streak on the North American hard courts to 54 matches.
"I fought hard today because I had to," Federer told reporters. "Today was very hard, I started badly and he had a big opportunity at the start of the second set but somehow I got out of it.
"It was a physical test, a mental test. I just always believe I can turn any match around and that's what happened today."
Under blazing sunshine, Federer got his 17th consecutive final off to a positive start, taking the first game to love.
But the 20-year-old Gasquet, who beat Federer last year at the Monte Carlo Masters, would not be intimidated.
He responded by storming through the next five games, committing just two unforced errors compared to a staggering 17 from the world number one on the way to wrapping up the first set in 31 minutes.
"I did a fantastic first set," said Gasquet, who has now twice reached a Masters Series final, losing both to Federer.
"I played wonderful. I know with Roger when you have some chances you have to do it."
ANOTHER GEAR
Gasquet kept Federer under pressure at the start of the second set and had triple break point before Federer shifted into another gear to win five straight points and hold serve.
Federer then broke Gasquet at the first opportunity and served out the set to level the match.
The Swiss was in no mood for another surprise defeat by Gasquet and, with the tension mounting in the third set, Federer seized control with a break to go up 3-2.
He never loosened his grip after that, ruthlessly ending the contest by easing through the next three games.
"I couldn't believe I started the second set so bad," said Federer. "That's like a key moment in the match. For me that was definitely the turning point."
Federer will now move on to Cincinnati where he will be looking to defend the title he won last year.
More from rediff