Federer saw off Marin Cilic for the 10th time in 11 meetings, winning 6-2, 2-6, 7-6 (7/4), 6-2 but only after a second set bust-up with umpire Emmanuel Joseph.
The 20-time Grand Sam title winner was handed a time violation at 1-3 down in the for taking too long between points.
"I don't even dare to go my towel anymore," he said to Joseph.
Federer, the oldest man in the draw at 39, lost his cool and the set before recovering to defeat former world number three Cilic.
Former US Open winner Cilic was also handed a time warning late in the third set.
Playing in only his second French Open since 2015, Federer goes on to face Germany's Dominik Koepfer for a place in the last 16.