Unseeded Marcos Baghdatis of Cyprus defeated the No. 12 seed 7-6 (4), 6-7 (5), 7-6 (3) in men's singles.
Raonic, from Thornhill, Ont., had 15 aces against Baghdatis in a match that lasted two hours 40 minutes. The Canadian opened the tournament by beating Marinko Matosevic of Australia 7-6 (4), 6-3.
In other second-round matches Wednesday, No. 2 Novak Djokovic of Serbia downed Bulgaria's Grigor Dimitrov 6-3, 6-2 and No. 4 Tomas Berdych of the Czech Republic defeated Italy's Andreas Seppi 6-3, 6-3.
American Sam Querrey upset No. 14 Kei Nishikori of Japan 2-6, 6-1, 6-4 and No. 16 Philipp Kohlschreiber of Germany fell 6-3, 6-4 to Feliciano Lopez of Spain.
On Tuesday, John Isner reached the third round by beating Kevin Anderson of South Africa 7-6 (3), 6-7 (8), 7-6 (7).
The second-seeded Djokovic won the China Open in Beijing last week for his fourth title of the year and 32nd of his career. He has won 66 matches this season, the most of any player on tour.
Djokovic didn't give Dimitrov a break-point opportunity and never lost more than one point in any service game. He also served four games at love.
"Very pleased with my serving in Beijing and obviously the first match today," Djokovic said. "So that's something that I've been working on, obviously. Relying on the serve in today's tennis is a big advantage. So I try to get as many free points as possible. It helped me a lot to defeat my opponent."
If Djokovic wins in Shanghai and Roger Federer loses before the quarter-finals, the Serb would reclaim the No. 1 ranking next week.
U.S. Open champion Andy Murray advanced to the third round in a walkover Wednesday after Florian Mayer of Germany withdrew because of a rib injury.
"I went to the gym this morning in the hotel, and he was in the gym at the same time," Murray said. "I didn't know until 15, 20 minutes ago."
Murray is the two-time defending champion at the tournament with a 9-0 record after winning finals against David Ferrer last year and Federer in 2010. The third-ranked Brit also won Olympic gold at the London Games and a title in Brisbane title earlier this year.
Fifth-seeded Jo-Wilfried Tsonga beat Benoit Paire 7-6 (7), 7-5 in an all-French match.Suggest a correction