Seeded third at a tournament for the first time since 2003, Federer arrived in Toronto to talk his career was starting to fade, but the Swiss has shined on the Canadian hardcourts and will now play champion Andy Murray for the title on Sunday.
Britain's Murray had earlier brushed aside world number one Rafa Nadal 6-3, 6-4 to spoil any chance of a dream final between the Spaniard and his great Swiss rival, who has battled tooth and nail to win two three setters and reach the Canadian final for the fourth time.
A day after gaining revenge on his Wimbledon conqueror Tomas Berdych in a nearly three hour match that was decided by a third set tiebreak, Federer was forced again to fend off a determined fightback from Djokovic.
Federer, twice a winner in Canada, raced through the first set in just 25 minutes and after surging ahead 2-0 in the second had looked poised for a quick match.
But he suddenly lost his way and Djokovic seized his chance, breaking Federer twice to send the match into a decider.
The third set swayed back and forth and appeared headed for another tiebreak until Federer broke Djokovic at 6-5 clinching the match on his first match point.
"Tonight I came out with all guns blazing," Federer told reporters.
"I played fantastic in the first set but in the second set Novak was able to raise his game and make it super competitive so I feel very happy to have come through.
"He fought bravely. He put his foot in the door before I could close it but I'm very happy to be back in the final," he added.
Federer will replace Djokovic has world number two on Monday and will set his sights on retaking number one from Nadal. The Swiss has spent 285 weeks at the top of the rankings and needs only one more to match Pete Sampras's record of 286.
COMPLETE PERFORMANCE
Murray, who needed to reach Sunday's final to retain his number four world ranking, can now focus on clinching his first title of the season and becoming the first back-to-back winner on the Canadian hardcourts since Andre Agassi in 1995.
It was a stunningly complete performance by the 23-year-old Scot who refused to be pushed around by the muscular Spaniard and in the end walked off with his fourth win in 12 career meetings - all coming on hardcourts.
"It's the surface I feel most comfortable on," Murray told reporters.
"I move better on hardcourt than on other surfaces.
"There are certain things the surface allows me to do against him that I can't do on the others. I've always played my best tennis on the hardcourt," he added.
Murray has been in impressive form on the North American hardcourts, also making the Los Angeles final, offering hope that he might make his long awaited grand slam breakthrough later this month at the US Open.
The Scot has come close to ending Britain's long wait for a men's grand slam singles champion, though he lost to Federer in the 2008 US Open final and in the Australian Open final this year.
Murray top seed in LA after Djokovic withdraws
Nadal and Djokovic pass tough tests in Toronto
Nadal slams UEFA over Real Mallorca exclusion
Roger Federer's advice to Andy Murray
Somdev fails to qualify for Toronto Masters