Sixth seed Raonic triumphed 6-3, 6-7 (3/7), 4-6, 7-5, 6-3 and goes on to face second seed Andy Murray, the 2013 champion, or 10th-seeded Czech Tomas Berdych
It was 25-year-old Raonic's first win on grass against a top 10 opponent and shattered Federer's hopes of going on to claim a record eighth All England Club crown and 18th major.
"There was a little opening and I took it," said Raonic who looked down and out in the fourth set.
After weathering an early storm, Federer had been in complete control of the semi-final, his 10th at the tournament, until the tie turned suddenly and dramatically in the fourth set.
Also Read
The 34-year-old, bidding to become the oldest finalist in 42 years, squandered three break points in the set and slipped from 40-0 up on serve in the 12th game.
Federer, whose last Grand Slam crown came at Wimbledon in 2012, had already required five sets to get past Marin Cilic in the quarter-finals, saving three match points in the process.
Raonic, nine years his junior, pounced for a 3-1 lead while Federer had to save two more break points in the sixth game.
The Canadian held hs nerve and claimed victory when Federer went wide with a weary forehand which condemned the Swiss star to his first loss in a Wimbledon semi-final.
Raonic finished with 23 aces and 75 winners while Federer converted just one of nine break points.
He carved out and converted the only break point of the first set for a 3-1 lead before unleashing the fastest serve of the tournament of 144mph (231.7km/h) in the fifth game.
Federer squandered four set points in the 10th game of the second set, the last of which off a sloppy backhand.
The Swiss soon went to another three set points and this time he pounced, levelling the match when a Raonic backhand stab drifted wide.
His seventh ace of the contest sealed the set in the 10th game.
With his coach John McEnroe commentating for British television, Raonic had to save two break points in the fifth game and another in the ninth of the fourth set.
However, in a remarkable 12th game, Federer was pegged back from 40-0 after serving up back-to-back double faults and Raonic levelled the semi-final on a third set point when the Swiss meekly teed-up an opportunity for the Canadian to pass him.
The fatigued legend saved a break point at 1-2 in the decider but only after jarring his left foot and knee in an awkward fall.
A breathtaking close-up rally at the net went in the Canadian's favour and he broke for 3-1 in what proved to be the crucial breakthrough.