The crowd on Arthur Ashe were stunned when the world number one approached Wawrinka and embraced him while trailing 6-4 7-5 2-1.
Djokovic has been bothered by a left shoulder injury all week, although it was not apparent during the opening two sets with Wawrinka reprising the sort of form which made him the champion in 2016.
But the Serbian took a medical time-out after dropping the second set, and three games into the third he decided enough was enough.
"It was the left shoulder," Djokovic confirmed.
"I congratulate Stan. He's a great player. I really wish him all the best the rest of the tournament.
"I don't want to talk about my injuries. I said that in the past. I'm sticking to that.
"I'm sorry for the crowd. Obviously they came to see a full match, and just wasn't to be. That's all it is."
The result means Wawrinka will face fifth seed Daniil Medvedev in the quarter-finals, while the draw has opened up for Roger Federer, who was in imperious form against David Goffin and had been expected to run into Djokovic in the last four.
Earlier, Medvedev revelled in his role as the villain of the tournament after beating Dominik Koepfer to reach the quarter-finals.
The Russian, who caused a stir by sticking his midle finger up at the crowd in a 'visible obscenity' two nights earlier, was jeered as he strode onto court in Louis Armstrong Stadium.
The majority of the spectators were firmly behind German qualifier Koepfer when he went a set and a break up.
But Medvedev eventually won 3-6 6-3 6-2 7-6 (2), before goading the crowd again with his celebration and then saying in his courtside interview: "Guys, continue to give me this energy. You are the best."
ESPN commentator Pam Shriver, referring to the mutual respect shown between Naomi Osaka and Coco Gauff 24 hours earlier, said: "The women are being so well behaved, and the boys are just misbehaving. Boys will be boys."
In the afternoon session Federer laid down a marker by dismantling Goffin.
The third seed dropped just four games, winning the last nine on the trot, for a brutal 6-2 6-2 6-0 victory in just an hour and 21 minutes.
If Britain's Dan Evans was feeling bad about the manner of his third-round defeat to Federer, he can surely take some comfort from the fact he won one more game than Goffin, the 15th seed.
Federer had looked susceptible in his opening two matches, dropping a set in both, but is since cruising through the gears.
Goffin, who broke Federer's serve early in the first set, won just seven points in the third, the Swiss finishing him off with a stunning backhand pass down the line.
Federer, looking for a 21st grand slam title, said: "Look, sometimes these scores just happen. You catch a good day, the opponent doesn't, then things happen very quickly.
"Maybe he struggled a bit early on. But I found my groove after a while and was able to roll really, and never looked back.
"David wasn't nearly as good as I expected him to be. He was struggling a little bit. I was able to take advantage of it, and I think that's the key.
"In a fourth round like this, if you can keep it nice, short, simple, you have to take them. I'm very happy."
Federer will face Grigor Dimitrov, the former world number three, in the last eight.
Bulgarian Dimitrov beat Alex De Minaur of Australia in straight sets, 7-5 6-3 6-4.