The seven-time champion suffered a shock 6-3, 6-7 (3/7), 4-6, 7-5, 6-3 defeat in a match where he crucially failed to convert break points in the fifth and ninth games of the fourth set.
The great Swiss, who won the last of his 17 majors at Wimbledon four years ago, looked heavy and flat-footed in the final set against a player who is nine years his junior.
He even stumbled and fell in the fifth set, lying face down in the turf of Centre Court where he has enjoyed his greatest moments.
"I hope to be back on Centre Court, to be very clear for you," said Federer, whose lengthy wave to all parts of the arena prompted speculation that it was indeed goodbye.
"I was looking at Centre Court as in thank you for the crowd. That's what I was going through, not thinking about this might be my last Wimbledon."
Had Federer made Sunday's final he would have been the oldest finalist since 39-year-old Ken Rosewall finished runner-up to Jimmy Connors in 1974.
His loss on Friday, in his 10th Wimbledon semi-final, followed a marathon five-set win from two sets down to beat Marin Cilic in the quarter-finals.
This year's Wimbledon represented the 15th anniversary of his stunning win over Pete Sampras -- when Raonic was just 10 years old -- although his first All England Club title only arrived two years later.
But Federer is enduring the toughest year of his career.
Injury forced him to skip the French Open ending a streak of 65 successive appearances at the Slams stretching back to 1999.
He has now failed to add to his 88 titles this year, his longest drought since 2000, and he arrived at Wimbledon having suffered back-to-back semi-final losses in Stuttgart and Halle, both on grass which has been his preferred surface of domination.
In an indication of changing times, his last-four loss in Stuttgart to Alexander Zverev was his first against a teenager in 10 years.
The defeat to Raonic still leaves Arthur Ashe as the oldest Wimbledon men's champion -- and the American achieved that feat a month shy of his 32nd birthday in 1975.
Federer, who underwent surgery earlier this year on the same knee he hurt on Friday, will be 35 next month.
He had made the final at Wimbledon in 2014 and 2015 losing to world number one Novak Djokovic on both occasions.
As the benchmark in the sport, Federer hasn't defeated the Serb at a Slam since the Wimbledon semi-finals in 2012.
Wimbledon has always been Federer's home-from-home even if his first two visits as a pony-tailed contender with a short fuse and dream one-handed backhand ended in first round losses.
But his fourth round defeat of seven-time winner Sampras in 2001 marked him out as the American's natural heir even if 2002 saw a woeful first round exit to Mario Ancic.
That blip was forgotten 12 months later when he won his first Wimbledon, spiking the heavy artillery of Mark Philippoussis in the final.
Since then, he has enjoyed more successes than setbacks.
Federer won the title every year between 2003 and 2007, adding two more in 2009 and 2012.
In between, he lost the 2008 final to Rafael Nadal in what is widely-regarded as the finest men's championship match in history, a five-set epic which ended in semi-darkness.
However, there was also a shock second round exit to world number 116 Sergiy Stakhovsky in 2013.
After his loss on Friday, he tried to take the pressure off the prospect that an eighth Wimbledon title may remain out of reach.
Federer was looking instead to the Olympics and then the US Open, as long as the injury he picked up against Raonic proves not to be serious.
"It's a dream to win my eighth here but it's not the only reason why I play tennis, otherwise I'll go in a freeze box now and come out before Wimbledon next year," he said.
"I know Wimbledon is important, but it's not everything.
"I have played 10 sets (against Cilic and Raonic). It's very encouraging for the season. I was insecure coming into Wimbledon."