Nadal finally got the break and Shapovalov did not get a point against serve until game eight - he only had two when the world number two closed out the first set by forcing the Canadian deep and wide before rushing to the net to close the angles. Nadal lost their only other match at the Rogers Cup in Montreal last summer. "I think this was probably one of the three matches that I played this way in the past 12 months".
Shapovalov was stretched to three sets in his opening two matches, against 15th-seeded Tomas Berdych and Robin Haase, and reached the semifinals of last week's Madrid Open.
Number one seed Simona Halep of Romania made it through to the quarter-finals before a ball was struck as her opponent, Madison Keys of the United States, had to retire hurt before she took to the court. But with my serve, I didn't lose many points.
While Fognini drop-kicked his racket onto the court after a miss early in the third set, it was Thiem who ultimately lost his cool.
"At the beginning, I really think that he was serving big".
Djokovic, back after a troublesome elbow injury, showed flashes of his formidable best as he beat Spain's Albert Ramos-Vinolas 6-1 7-5 and will meet Japan's Kei Nishikori in the next round.
Defending champion Alexander Zverev needed eight match points before completing a 7-5, 7-6 (11) win over Kyle Edmund.
The 16-time Grand Slam victor next takes on Canadian teenager Denis Shapovalov who dug deep in a 7-6 (7/3), 6-7 (5/7), 6-3 win over Robin Haase of the Netherlands. "[Fognini] is a tough player and I'm looking forward to the challenge".
Nadal, who has not won the Italian Open since 2013, next faces Fabio Fognini, who beat Peter Gojowczyk 6-4, 6-4.
Halep now needs to progress further than No. 2 Caroline Wozniacki to stay in top spot.
Kontaveit, who also beat Williams last week in Madrid, next plays either second seed Wozniacki or Latvia's Anastasija Sevastova for a place in the semi-finals.
The Romanian, a finalist in Rome past year, is on her way to holding on to top spot as she next plays France's Caroline Garcia who dumped out US Open champion Sloane Stephens 6-1, 7-6 (9/7).
The victor will play Anett Kontaveit, who ousted 1999 champion Venus Williams 6-2, 7-6 (3).
Important results: Women: Third round: Simona Halep w/o Madison Keys; Jelena Ostapenko bt Johanna Konta 2-6, 6-3, 6-4; Elina Svitolina bt Darya Kasatkina 0-6, 6-3, 6-2; Angelique Kerber bt Maria Sakkari 6-1, 6-1.