The Serbian battled a shoulder injury in his second-round win over Juan Ignacio Londero but appeared to suggest his condition had improved after a third-round defeat of Denis Kudla.
However, the World No. 1 was second best throughout against the 2016 champion and called it quits after he dropped his serve to give Wawrinka a 6-4, 7-5, 2-1 lead in the third.
Wawrinka, who is in pursuit of his fourth major title, will play Daniil Medvedev for a place in the semi-finals.
Wawrinka made an outstanding start to proceedings, finding immediate success with his backhand, and he struck the opening blow by breaking to take a 3-2 lead.
The Swiss saved a pair of break points in the subsequent game, holding with the help of three successive aces, before a crunching forehand enabled him to wrap up the set.
Djokovic provided an instant response to start the second set as Wawrinka pushed a backhand long.
However, Djokovic was uncharacteristically sloppy on serve and a pair of double faults followed by an incredible backhand around the net post from Wawrinka laid the platform for a break back that came when the Serbian went long himself at the end of a captivating rally.
A love hold from Wawrinka followed and Djokovic then came under further pressure as he was forced to save a break point before completing a difficult hold with a sublime backhand volley.
Wawrinka, by contrast, went another service game without dropping a point, and a stunning backhand return gave him two break points. He only needed one as Djokovic produced a forehand volley lacking both power and placement.
The second set was sealed in similar fashion as Djokovic failed to execute a backhand drop shot. He received treatment on his shoulder before the third, which he started with a confident love hold.
That proved a false dawn, though, as Wawrinka responded with a comfortable hold before a break to love came his way with a Djokovic double fault that prompted the 16-time Grand Slam champion to cross the net and shake hands.
For in-depth, objective and more importantly balanced journalism, Click here to subscribe to Outlook Magazine