The second-seeded Federer, who is bidding to win a third Shanghai Masters title, dominated in the first set, but was tested in the second.
Federer struggled in the tiebreaker, falling behind 1-4, but eventually managed to pull even. He won his lone match point when he executed a forehand crosscourt volley.
"I focused and had good energy, because sometimes, you know, when you travel around the globe, you're missing a bit of energy," Federer said. "Those first few games or matches can be sometimes a bit tricky.
"I think [my] serve was solid. I was hitting my spots and really was never in trouble there."
The last time the two faced each other was in the 2015 Shanghai Masters, where the Spaniard shocked Federer by taking the three-set encounter. On Tuesday, Federer admitted he had that match on his mind.
"All the time," Federer said. "The truth, yeah, I was thinking about it. Watched highlights. Remember how it felt. I had my chances. I won many more points that time than I lost, so I should have actually won that match."
Similarly to Federer, third seed Daniil Medvedev of Russia never offered his opponent, British qualifier Cameron Norrie, a break-point opportunity in securing a 6-3, 6-1 second-round win in 54-minutes.
"I'm really happy with my performance, really happy with the score and am really looking forward to the next round," Medvedev said. "It was my first match here in Shanghai after having a few weeks off, so I was a little bit stressed about how my level would be.
"I managed to get out of there in less than an hour."
Medvedev has reached the final of the last five tournaments he's played, including his first Grand Slam final showing, which came at the US Open.
The 12th-seeded Coric was runner-up in Shanghai last year, losing to Novak Djokovic in straight sets in the final.