Raonic, who had a first-round bye, hit 21 aces to Bolelli's seven but converted just one of eight break point opportunities.
"There were many close games, but I couldn't make the most of my chances," Raonic, from Thornhill, Ont., said. "I served better as the match went on, but he made it through when it mattered the most."
Bolelli broke the longest losing streak against top-10 opponents in the Open era, with his first victory after 35 defeats.
The Italian faces seventh-seeded Gael Monfils of France in the quarter-finals.
Third-seeded Ernests Gulbis of Latvia was eliminated in a 6-3, 6-4 defeat to Frenchman Jeremy Chardy.
Chardy has another difficult test, against compatriot Gilles Simon, after the fifth-seeded player beat Borna Coric 6-2, 3-6, 6-3.
No. 2 Stan Wawrinka is now the highest-ranked player in the tournament after the Swiss player eased past wild card Benoit Paire of France 6-2, 6-3 in less than an hour.
Wawrinka, who has won more matches than any other player on the circuit this year, moved to a 15-1 record as he booked a quarter-final match against Sergiy Stakhovsky.
Another seeded player, No. 6 David Goffin of Belgium, retired with a rib injury when losing 5-1 to Austria's Dominic Thiem.
The 21-year-old Thiem next plays Roberto Bautista-Agut.Suggest a correction