In a closely-fought battle, the players could not be separated in the first set until the 21-year-old upped his game in the tie-break.
But Federer responded to take the second set at a canter, before needing just one break point to seal the all-important advantage in the third.
Ultimately Raonic's inability to make an impression on the Federer serve proved the difference as he failed to secure a single break.
World number two Rafael Nadal had no such difficulties as he eased past fellow Spaniard Marcel Granollers 6-1 6-4.
Nadal won eight of the first nine games and, though his standard dipped thereafter, he maintained his focus to progress.
He will next face Alexandr Dolgopolov, who beat Marcos Baghdatis 6-4 5-7 6-4, and Nadal told www.bnpparibasopen.com: "He's a crazy player because you can expect everything.
"He can play really aggressive, he can play very fast, he has a very good serve, and the ball is going too fast sometimes."
Sixth seed Jo-Wilfried Tsonga hit back from behind to defeat Czech veteran and 28th seed Radek Stepanek 6-7 (7/2) 6-3 6-2 in a match lasting two hours and 17 minutes.
Ninth seed Juan Martin Del Potro beat Fernando Verdasco 6-2 7-6 (8/6), but fifth seed David Ferrer was a surprise casualty as he fell 6-4 6-3 to Denis Istomin of Uzbekistan.
Tenth seed Janko Tipsarevic followed him out of the tournament as he lost 6-3 3-6 6-3 to David Nalbandian.
In the fourth round of the women's draw, Victoria Azarenka extended her winning streak since the start of the season to 20 matches by making short work of Julia Goerges.
The world number one was expected to have to fight hard to repel the in-form, 15th seeded German, who beat Caroline Wozniacki en route to the final of the Dubai Tennis Championships last month.
But Azarenka needed just an hour and nine minutes to swat away Goerges' challenge 6-3 6-1 and reach the quarter-finals.
In the quarter-finals she will face Polish fifth seed Agnieszka Radwanska, who led Jamie Hampton 6-3 4-6 3-0 when the American retired hurt.
"I think it's going to be a tough match, as usual. We have really tough battles," said Azarenka. "I'm really looking forward to playing her again. She's a great player and a very good challenge for anybody to play."
Second seed Maria Sharapova also made light work of her fourth-round match, beating Italy's Roberta Vinci 6-2 6-1, to set up an all-Russian quarter-final against Maria Kirilenko.
Kirilenko beat another Russian, Nadia Petrova, 6-1 5-7 6-2.
Ana Ivanovic stunned Caroline Wozniacki 6-3 6-2 in a battle of two former world number ones.
Wozniacki's difficult season after she surrendered her number one status in Australia.
There were also wins for Marion Bartoli, Li Na and Angelique Kerber.