Trailing by two sets, Djokovic shook hands with Wawrinka and conceded the match when he was trailing in the third set and later confirmed he was suffering with a left shoulder injury that meant he simply could not continue.
The 16-time Grand Slam victor, who had been struggling with the injury throughout the tournament, was forced to end his US Open campaign in the third set, having lost the opening two sets to Swiss 23rd seed Wawrinka.
Last year's US Open victor had shown signs of his injury in the second round against Juan Ignacio Londero, where he needed treatment three times before eventually overcoming the Argentine in straight sets.
The New York crowd, angered by what tournament organisers called Medvedev's "visible obscenity" two nights earlier, were firmly behind Koepfer when he went a set and a break up.
While the NY crowd was clearly unaware of the reason for Djokovic's exit, he was booed as he left the court and gave a thumbs-up gesture in return, as he appeared to vent his annoyance.
The top-ranked Djokovic tried to make it 12 for 12 in US Open fourth-round matches in a night match against Stan Wawrinka, a rematch of Wawrinka's victory in the 2016 final at Flushing Meadows.
"It helped me big time knowing I have the game to beat him on that court", Wawrinka said.
But Djokovic, victor of four of the past five Slam events and 16 overall, remained bullish about his chances of eventually catching and surpassing long-time rival Roger Federer, who holds the men's record of 20 major titles.
Federer, a five-time US Open champion with 20 Slam titles, advanced to the US Open quarter-finals for the 13th time by routing Belgian 15th seed David Goffin 6-2, 6-2, 6-0 in only 79 minutes. "It's going to be interesting match to play against him". "You just know when you know, I guess".
Despite his success on the court, Djokovic has yet to receive the level of adulation given to rivals Roger Federer and Rafael Nadal, and judging by the reaction of the spectators in NY, this won't help his cause with fans. This loss, if that's the right word for it, is a precious opportunity gone to waste.
"For sure I could see some little thing that he was in trouble". Djokovic simply gave a thumbs-up gesture as he walked off the court due to the shoulder pain. It wasn't a taunt.
"I'm sorry [for them]", he said. "I was quite confident with the level I had but you never know when you are playing the number one player in the world". "But obviously I just came off the court, so of course it hurts. It is what it is".