The 35-year-old Swiss star will be chasing his ninth title on Sunday at the grass-court tournament in Halle, Germany.
Federer was serving for the match but he was broken by the 21-year-old Russian. Khachanov then missed two set points before Federer took it to the tiebreaker. Federer advanced when Khachanov lifted a backhand long on match point.
"I thought it was extremely close, especially that second set," Federer said afterward. "I'm still just very happy how I was able to close it out in the breaker.
Federer saved four of the six break points he faced overall and converted three of his five opportunities. He had never faced the 6-foot-6 Khachanov before Saturday.
"It was all a little uncertain because I don't know him that well," Federer said. "It's warm, it's hot, I'm a little bit tired. It was a difficult match."
Federer, who won the Australian Open in January for his 18th Grand Slam title, decided to skip the clay-court season, including the French Open, to prepare for the grass and hard-court seasons, with his eye on Wimbledon, where he is a seven-time champion.
"Everything has been geared toward that for the past 12 months and I'm happy with how I feel at the moment," said Federer, who will be going for his 92nd career title in what will be his 140th final.
Federer also will go for his ninth title in the German city, which would mark the first time he has won a tournament as many times. He first reached the Halle final in 2003 but has not played for the trophy at the ATP World Tour 500 tournament since 2015.
Federer has yet to drop a set in Halle this week. He improved his all-time record at the tournament to 58-6 and is 23-2 on the season. He has reached the final in four of his six tournaments this year.
Federer, ranked No. 5 in the world, lost to Zverev in last year's Halle semifinals but beat him last year in Rome.
Zverev, Germany's top-ranked player at No. 12, fired 11 aces and converted four of eight break opportunities to beat Gasquet in under two hours. He will be going for his fourth title of the season on Sunday.