The number one seed appeared to be cruising at 4-2 in the third set, but became distracted when the stadium floodlights came on - he lost four straight games and the set, growing visibly upset with a crowd that cheered the Shapovalov comeback.
However, he soon regained his composure and raced through the final set as Shapovalov's game faded.
US Open
Medvedev ‘would love’ to see Djokovic play at the US Open
Despite showing flashes of brilliance, the 19-year-old Shapovalov lacked the consistency to trouble the world number one.
The Canadian's ambition was encapsulated by an attempted tweener at 0-2 in the third set - but Djokovic dismissively swatted it away to underline the gulf in class between the pair. Better times lie ahead for the 25th seed.
Djokvoic faces another young gun in the fourth round - 22-year-old Russian Daniil Medvedev.

Turning lights on made 'no sense'

Serbia's Novak Djokovic reacts after a point against Canada's Denis Shapovalov

Image credit: Getty Images

Speaking on court, Djokovic said he could not understand why the officials turned the lights on.
"I think there was no sense to turn on the lights on the court at 5pm when we have another four hours of daylight.
"[Directed to crowd] Did you guys see the ball well? I saw them well too. I thought it was completely unnecessary. The explanation I got was for TV reasons, so I hope the viewers enjoyed it!
"I just tried to stay in the moment and weather the storm. Denis played well towards the end of the third and I made some unforced errors, got him back in the match.
"He showed his quality and why we're going to see much more from him in the future."
US Open
'It’s BS' – McEnroe says Djokovic should be allowed to play US Open
US Open
Djokovic at US Open: America relaxes Covid rules - but star faces travel wait
12/08/2022 AT 08:58