Swiss 23rd seed and 2016 champion Wawrinka led Djokovic 6-4, 7-5, 2-1 when the Serb quit, having received treatment on his troublesome left shoulder before the start of the third set.
“It's never the way you want to finish a match. I'm sorry for Novak. He's an amazing champion,” Wawrinka said.
Djokovic, who has won four of the past five Grand Slam events and 16 overall, had struggled with a painful left shoulder during his second-round win over Juan Ignacio Londero.
He said he felt “almost pain-free” following a straight-sets defeat of Denis Kudla in round three, but the problem resurfaced against Wawrinka in the first meeting between the pair since the final here three years ago.
“I want to keep my level of tonight. I think I was playing super good tennis. I'm happy to be back,” said Wawrinka, who will meet fifth seed Daniil Medvedev in the quarter-finals.
“It helped me big time knowing I have the game to beat him on that court.
“I was feeling great. When I came to practice here I was moving well, playing well. I was quite confident with the level I had but you never know when you are playing the number one player in the world.”