Edmund, who was aiming to reach the last 16 for the second consecutive year, started the match brightly winning the first set 6-3 over his talented Candanian opponent.
But Shapovalov leveled the match, shaking off his early nerves and winning the second set 6-3.
Edmund then begun to experience pain in his neck midway through the third set and received treatment at the next change of ends.
The British number two lost the set 6-3 and after one game in the fourth, decided to retire.
Shapovalov said: “It is never good to win this way. I hope it is not too serious. Kyle has been playing great tennis and if he keeps it up he will be doing really well.
“In one game he hit a second serve and I heard him grunt like he had hurt something and he called the trainer. It is very unfortunate but I am happy to be in the fourth round.”
Shapovalov reaches the fourth round of a major for the first time in his career and will face Pablo Carreno Busta of Spain.
He added: “Carreno Busta is an unbelievable player. He plays big and goes for his shots it. It will be a tough match up but I have been playing tough guys so hopefully I can keep going.”
2014 champion Marin Cilic is also out of the tournament after being knocked out by Argentine 29th seed Diego Schwarzman 4-6 7-5 7-5 6-4.
It means the highest ranked player in the bottom half of the draw is now world number 15 John Isner and there will be a first time Grand Slam finalist from the bottom half of the draw.