0306 GMT January 23, 2020
Federer, 36, proved the stronger in the final set, winning 7-6 (8-6), 5-7 6-1, BBC reported.
Germany's Zverev, seeded third, can still qualify for the semifinals on his debut appearance at the O2 Arena.
He will play American Jack Sock in his final group match later today, with the winner to progress to the last four.
Federer made it through to the semifinals for a remarkable 14th time at the season finale, but was pushed hard for two sets by the leading light of the new generation.
Zverev showed his class with some brilliant serving in the first set, making 76 percent of his first serves, but it was still not enough.
The German had three chances to break in the opening game and would later lead 4-0 in the tie-break, before a rash of forehand errors allowed Federer to come back and take it.
An early break of serve in the second set looked to have the Swiss in complete control, but from 2-0, 30-0, he surprisingly hit successive double-faults and lost his way for the next few games.
Clearly rattled by his wavering form and increasingly confident rival, Federer eventually cracked in the 12th game to send a forehand wide and give up the set.
The adrenaline was coursing through Zverev but the effects had worn off three games later, when a tired double fault opened the door for Federer to get the key break, celebrating with a loud "Come on!"
Four errors in succession saw Zverev hand over the double break and it became three in a row when the German double-faulted on match point after two hours and 13 minutes.
Federer can now look forward to a final group game against Cilic knowing there is only pride, and the wish to maintain his winning run, on the line ahead of Saturday's semifinals.
"I'm excited for Alex's future. He's a wonderful guy and a great, great player," said Federer.
"I'm happy and relieved that I can play freely against Cilic, instead of it being a nail-biter. It's been a tough group so to be through in two matches is great."
Eighth seed Sock earlier beat Croat fifth seed Marin Cilic 5-7, 6-2, 7-6 (7-4) in the second round of matches in the Boris Becker Group.
"That was a tough one for sure," said Sock.
"It's been an interesting morning so far, the fire alarm went off at 4am and we had to exit the building. But I love playing here in London, it's an amazing atmosphere, you make me feel like [I'm] home.
"I'm just excited to win and keep myself alive."