That set up a fascinating third set and Federer drew first blood to take an early lead, but Cilic refused to back down as he broke back.
A tiebreak was going to decide which way the match would swing and Federer showed his class in barely putting a foot wrong to take the decisive set.
Losing the third set appeared to take it out of Cilic, giving Federer all he needed to get the match won in the fourth.
He now faces Dominik Koepfer in the third round and remains on course to face Novak Djokovic in the quarter-finals.
But a potentially difficult fourth-round clash with Matteo Berrettini could await with the Italian taking on Kwon Soon-woo.