The Swiss had led by two sets to love and had a match point but collapsed late in a lengthy decider to crash out 6-2 7-6 (7-5) 5-7 4-6 11-13 in a contest that lasted more than four hours.
Federer will be playing in his 53rd Grand Slam last-eight when he tackles Kevin Anderson, the eighth-seeded South African.
Meanwhile Novak Djokovic ended his near two-year absence from grand slam semi-finals by booking a place in the last four at Wimbledon.
"It would take an unbelievable serving performance and for Roger had a bad serving day to cause an upset".
In the end, it just wasn't meant to be Roger Federer's year at Wimbledon. As the match went on, I gave it my all.
Serbia´s Novak Djokovic celebrates after beating Japan´s Kei Nishikori 6-3, 3-6, 6-2, 6-2 during their men´s singles quarter-finals match on the ninth day of the 2018 Wimbledon Championships.
Cardi B counter 'sues' ex manager for R203 million
Cardi's legal team also claims that Raphael's companies, KSR and WorldStar, failed to give Cardi B a full accounting of her funds. Cardi B is being represented by Paul LiCalsi , an entertainment attorney who has represented major artist such as The Beatles .
Anderson never had made it beyond the fourth round at Wimbledon until this week, carried by his booming serve. I think it went in spells a bit also, how I was able to return his serve.
'I don't think it really mattered, to be honest. Shouldn't really happen, but thankfully they do for me.
This is his best run at Wimbledon since that 2015 success as he lost in the third round in 2016, and then retired hurt in the quarter-finals against Tomas Berdych 12 months ago.
Kevin Anderson, the big South African who winds down from tennis by reaching for his guitar, admits he needs to be right on key from the start of his Wimbledon quarter-final against eight-time champion Roger Federer.
The shock of the tournament appeared to be edging closer when Anderson moved 30-0 up in the third game, but Federer relied on his serve to salvage a hold, doing the same four games later to dig himself out of another hole after Anderson had also recovered from 30-0 down. And it was Federer who blinked, double-faulting to face a break point at 11-all, then slapping a forehand into the net to cede the key break.
Six times Anderson was required to hold serve to stay alive and each time he was equal to the task.
It was Federer who faltered at 11-11, double-faulting to hand Anderson a break point which he converted when the defending champion's tired forehand smacked the net.