The Spaniard dominated the first set before succumbing 1-6 7-5 6-2 to the Canadian world number 16.
Nadal was limping towards the end of the match, which will be a concern with the French Open starting on 22 May.
"It started to hurt me again in the middle of the second set, and it became unbearable," he said post-match.
The 35-year-old has only just returned from a six-week absence with a rib injury. He has also been suffering with the rare degenerative foot condition Mueller-Weiss Syndrome for more than a year and missed last year's Wimbledon with it.
"It's a pain that comes and goes," he said. "Sometimes stronger, sometimes less. Today was crazy. Maybe in two days, it will be better. I don't know how it will be in two days, in a week. I really don't know."
In the late-night match, which ended with Nadal's earliest exit in Rome since 2008, he dominated a one-sided opening set with electric returns of serves.
Shapovalov showed grit in a determined second-set comeback, opening up a 4-1 lead before Nadal forced a tie-breaker, despite a series of unforced errors.
Nadal, who has been dogged by foot injuries throughout his career, was visibly labouring towards the end, and lost 17 of the last 20 points of the match.
"I'm not injured, I'm a player who lives with this injury," he added. "There's nothing new. Unfortunately, my daily life is difficult.
"Even so, I do my best. Of course, sometimes I find it hard to accept the situation. It's frustrating sometimes when I can't train normally for several days."
He added that he still has hope of making the French Open, a tournament he has won 13 times.
"I have to accept the situation and fight," he said. "I can't say anything more. I don't know if I should rest or train, but I still have a goal in a week and a few days. I will dream of this goal."
Earlier, Novak Djokovic cruised past old rival Stan Wawrinka to reach the quarter-finals.
The pair have met twice in Grand Slam finals, Wawrinka winning on both occasions, but in Rome world number one Djokovic won comfortably, 6-2 6-2.
Wawrinka, 37, now ranked 361st in the world, was also making a comeback after a year out with a foot injury.
He struggled physically and made a series of errors as Djokovic controlled with early breaks in either set.
Djokovic will play eighth seed Felix Auger-Aliassime in the last eight of the clay-court event after the Canadian beat American Marcus Giron 6-3 6-2.
Serb Djokovic is chasing a sixth title in Rome but his first of the year as he builds towards the French Open later this month.
Wawrinka's wins in the previous two rounds were his first since making his comeback in March.