The 34-year-old seven-time champion also claimed a new record for Grand Slam match wins of 307 as he made a 40th semifinal at the majors.
The Swiss won in dramatic style, pulling back the match after initially going two sets down.
The tension on Wimbledon's centre court -- now bathed in sunshine after a rainy first week to the championship -- reached fever pitch as Federer levelled at two sets a piece after a rollercoaster of a tie-break in the fourth.
He had already fended off three match points earlier in the set.
But Federer grabbed the momentum and broke for a 5-3 lead in the decider, racing to a famous victory with back-to-back aces.
The tension was almost too much for his fans.
I have to go for check up Roger Federer almost gave me a Heart-Attack...@rogerfederer Thank God he did it— Ditiro Seatla (@Zee23294) July 6, 2016
"Marin is such a wonderful player and I knew I was in so much trouble in the third set and in the fourth," said Federer after the match.
"I wasn't seeing his serves, he had one chance and took it and then I was down 2-0. He was playing very well and reading my serve and I couldn't read his.
"I just tried to stay in the match and hoped for his level to drop and get a bit lucky. That happened and obviously the breaker was crazy.
"My legs and back were there and serving was key, plus mentally this will give me a hell of a boost."
His dramatic triumph was his 84th win at Wimbledon and gives him a semifinal against Canada's Milos Raonic.