Cilic, who lost a Wimbledon final in straight sets to Federer last July, owns just one win from 10 meetings with Federer, a U.S. Open semifinal in 2014.
The Croatian got out of trouble by winning the second set in a tiebreaker only to see Federer strike back by taking the third.
The pair alternated as Cilic pulled even at two sets each.
But Federer started the fifth set with a break and piled on another before clinching the record-setting win on the first of three match points on Cilic's return error.
"I'm feeling a little bit obviously disappointed, which is normal," Cilic said. "It was a big battle, five sets. I managed to turn it around.
"In the fourth set, it was a big boost for me with the game that I played on 3-2 when he was serving. Then that lifted me a lot up. I started to play great tennis.
"I was hitting the ball great. I was just playing phenomenal. Then first game of the fifth set was more or less crucial at the end with having those four break points that I didn't convert.
"It just ran away from me. But I'm really happy with the performance. It was difficult with conditions."
Federer said that his thoughts may have intruded onto his tennis at points during the tight match.
"I got off a flyer, but I froze a bit in the tiebreaker at the end of the second set. I got nervous and couldn't take control.
"I got tight but Marin helped me a bit in the third and fifth sets (with errors). But he was calling the shots in the fourth.
"My mind was all over the place, I told myself not to mess it up."
(c)2018 Deutsche Presse-Agentur GmbH (Hamburg, Germany)
Visit Deutsche Presse-Agentur GmbH (Hamburg, Germany) at www.dpa.de/English.82.0.html
Distributed by Tribune Content Agency, LLC.