Playing his best when he absolutely needed it most, the seven-time champion finished with his 27th ace to complete a 6-7 (4), 4-6, 6-3, 7-6 (9), 6-3 victory on Centre Court against the player who knocked him out in semifinals of the US Open two years ago.
"Well, a lot happened out there," Federer said, summing up the 3-hour, 17-minute battle filled with tension, momentum swings and crucial points.
"I knew I was in so much trouble in the third, and then again in the fourth," he said. "I'm really, really pleased and just ecstatic I was able to come through somehow."
It was the 10th time in Federer's career that he has erased a two-set deficit to win in five sets. This was also his 80th match win at Wimbledon, which equals Jimmy Connors' record. Federer also matched Connors' record of reaching the Wimbledon semifinals 11 times.
What's more, Federer is now two wins away from the all-time record for Wimbledon men's titles. He's currently tied with Pete Sampras and 1880s player William Renshaw with seven.
Federer's semifinal opponent will be sixth-seeded Milos Raonic, who lost serve only once and downed No. 28 Sam Querrey 6-4, 7-5, 5-7, 6-4 on No. 1 Court.
Querrey had knocked out No. 1 Novak Djokovic in the third round on Saturday, but came up short in his bid to become the first American to make it to the semifinals of a Grand Slam since Andy Roddick reached the final four at Wimbledon in 2009.
The other semifinal will feature No. 10 seedTomas Berdychagainst the winner of the Andy Murray-Jo-Wilfried Tsongamatch.
Berdych,the 2010 runner-up at the All England Club, beatLucas Pouille 7-6 (4), 6-3, 6-2 on Court No. 1.
The 34-year-old Federer will now play in his 40th Grand Slam semifinal. He's the oldest man to get this far at Wimbledon since Ken Rosewall finished runner-up in 1974 at the age of 39. If Federer wins the title, he'll become the oldest men's Wimbledon champion in the Open era.
The third-seeded Federer looked down and out after falling behind two sets to love against No. 9 Cilic, a 6-foot-6 (1.98-meter) Croatian who kept holding serve, attacking on returns and dominating rallies with his big forehand and two-handed backhand.
It seemed like a replay of their last meeting, when Cilic swept Federer in straight sets in the semifinals en route to the 2014 US Open title.
"I wasn't seeing his serves anymore," Federer said. "Next thing you know you're down two sets to love on grass. I thought he was playing very well, US Open-esque. On the return he was reading my serve. On the serve, I couldn't read his serve."
But Federer gradually worked his way back into the match, breaking for the first time to go up 5-3 in the third, saving three match points in the fourth, and playing flowing grass-court tennis on his favorite stage.
After ripping an ace on match point, Federer wagged an index finger in the air to show who was No. 1. He walked off to a standing ovation from an adoring crowd that helped will him to victory.
"It wasn't going well for me, so for me it was about staying in the match," Federer said. "Somehow I hoped for his level to drop maybe a little bit, and get a little bit lucky. That's exactly what happened."
He cited a key point in the third set, at 3-3, love-40 on his serve, facing three break points.
"I have to pick up a half-volley," Federer said. "I mean it could go in the stands. It stays in. Next thing you know it's like you're still in the match and you can turn it around."
Federer held serve for 4-3, then broke in the next game, with Cilic double-faulting on break point. The momentum had changed.
In the fourth set, Cilic had more chances to put Federer away but couldn't. Federer saved two break points at 2-2, hitting three straight aces and a service winner to finish the game.
Cilic then earned his first match point with Federer serving at 5-4, but hit a forehand return long. Another match point came at 6-5, and Federer responded with a 120 mph ace.
Match point No. 3 came at 7-6 in the tiebreaker. Cilic failed to take advantage of Federer's second serve, hitting another forehand return into the net.
Federer wages epic comeback to reach semis
After losing the first two sets, Roger Federer roars back for an incredible comeback to defeat Marin Cilic and reach the semifinals at Wimbledon - Federer's 307th Grand Slam singles win, the most for a man or woman.
Federer: I feel sorry for Cilic, but my dream continues
Roger Federer talks about his gutsy five-set victory over Marin Cilic in the quarterfinals at Wimbledon.
The Federer point that made Bradley Cooper do this
Bradley Cooper can't believe this leaping, spinning, overhead backhand that the always-graceful Roger Federer made at the net during his quarterfinal match at Wimbledon.