The 25-year-old, who has reached the final of a Grand Slam for a first time in his career, trailed entering the fourth set, but won the last two to record a shock 6-3 6-7 4-6 7-5 6-3 victory over the world number three.
Federer launched a comeback from two sets down in his quarter-final against Marin Cilic, and he soon found himself playing catch-up in this match too as Raonic claimed an early break to move into a 4-1 lead.
It was the only break point that Federer gave up in the opening set, but it would prove to be all that Raonic needed to move into a 1-0 lead as he comfortably saw out the set.
Federer had the chance to restore parity again when he created four set points in the 10th game of the second, but Raonic held out and ultimately forced a tie-break that the third seed won 7-3.
Dreams of an 18th Grand Slam title - and a first since 2012 - got even closer for Federer when he recorded his first break of the match in the seventh game of the third set, and three consecutive love games on his own serve saw him move into a 2-1 lead.
The Swiss star created two more break points in the fifth game of the fourth set too, but this time Raonic was able to survive and went on to pick up the break himself in the final game with his third set point.
The fifth and final set was ultimately decided by one break of serve as Raonic broke at 1-2 to take charge on Centre Court, before serving it out in style to book his spot in the final, where he will face either Andy Murray or Tomas Berdych on Sunday.