The Scot made a forceful start and claimed a crucial break of serve in the third game to edge a high-quality opening set.
Federer responded well in the second set as both players served with accuracy and power to force a tense tie-breaker.
The Swiss star hit a pair of brilliant backhand winners under pressure to edge a tight breaker and level the match at a set apiece.
Murray did not dwell on that disappointment and quickly began to control the third set on his forehand side, forcing Federer to chase a succession of passing shots.
Despite saving break point Federer eventually wilted on serve and handed his opponent the third set by six games to three.
The pace slowed considerably in the fourth to Federer's advantage as he broke Murray's serve, thanks to a series of unforced errors.
Murray trailed 4-1 but punished some poor shot selection from Federer to break back and keep the fourth set alive.
Federer had two break points to reclaim the advantage but once again Murray showed resilience to survive.
Murray quickly broke back to love and had a chance to serve for the match but this time Federer responded to send a topsy-tuvry fourth to a tie-breaker.
A dominant tie-break performance from Federer sent the match into a fifth-set decider as Murray struggled badly on his second serve.
Despite leveling the match Federer faded at the start of the fifth set, allowing Murray to regain control with an early break of serve.
This time the Scot kept the pressure on to finally close out a bruising encounter and book a rematch with Novak Djokovic in Sunday's final.