"I couldn't chase the lines very well, so I couldn't hit any winners, but I really tried to play in a way where I was not going to just lose it. I gave him a chance to win, and he didn't, so I took it at the end," he said.
Coric had two match points in the tiebreaker, but he was unable to put Federer away.
"It was very tight. I got very lucky again today already like in Madrid. It's nice to get lucky I guess sometimes. I've lost a lot of heartbreakers throughout the years, so it's nice to win these and the atmosphere was fantastic. People were going crazy. It's exactly how you want the atmosphere to be," Federer said.
The 37-year-old Federer, who had not played in Rome since 2016, beat Portugal's Joao Sousa 6-4, 6-3 in a second round match earlier on Thursday.
Rain led to the cancellation of all matches on Wednesday, forcing Federer, who has avoided clay in recent years to avoid excessive wear-and-tear on his body and prolong his storied career, to win two matches in one day to advance to the quarterfinals.
The next opponent for Federer, who has won a record 20 Grand Slam singles titles, will be the winner of the match between rising Greek star Greek Stefanos Tsitsipas and Italy's Fabio Fognini.