Murray had somehow scraped through an ugly match against Czech Jiri Vesely in the third round and initially looked to be playing much better against Raonic.
However, the Canadian struck at the end of the second set and Murray let an early lead in the third slip away.
Asked after his win over Vesely what the main challenge of facing Raonic would be, Murray said with a wry smile: "To get a serve back."
The Canadian hit 33 aces in his first match and Murray barely moved as a 140mph bullet flew past him on the first point.
Two more followed in the opening game, and it was no surprise that it was the Wimbledon champion who was having more trouble holding serve.
Raonic forced a break point in the sixth game but Murray played a rock solid point to save it.
He looked like a different player to the one who struggled so badly against Vesely, and when Raonic's level suddenly dropped in the ninth game, he pounced.
The 26-year-old then made it 10 points in a row with a love hold to clinch the set.
It was a little reminiscent of his most high-profile meeting with Raonic, at the US Open in 2012, when having ground out a win over Feliciano Lopez he met the in-form Canadian in the fourth round.
But what had been tipped as a possible upset turned into a Murray masterclass that left Raonic gushing in admiration.
The Canadian was staying with his opponent this time, and breaking the Raonic serve is never an easy business.
Murray was all too aware of that and vented his frustration at his support box when what he perceived as an opening slipped away.
Raonic's forehand was a liability at times but when he did find his range it was capable of doing plenty of damage, and a cross-court winner brought up a break point in the eighth game of the second set that Murray saved with an ace.
But the Canadian sensed there was a chance to avoid a tie-break, and when Murray missed a routine forehand on the first point at 5-6, Raonic pounced.
Murray was furious with himself and sat on his chair with his head under a towel as his opponent headed off for a bathroom break.
The fifth seed claimed the first break of the decider to lead 2-1 but then played a sloppy game to give it straight back, and Raonic made the momentum swing count with another break to make it 4-2.
Murray saved one match point at 2-5 but Raonic took his second with a forehand winner to move through to a quarter-final against Alexandr Dolgopolov, conqueror of Rafael Nadal in round three and Fabio Fognini yesterday.