Konta earlier became the first British woman to reach the last eight of a Grand Slam in 32 years with a stunning 4-6 6-4 8-6 win over Ekaterina Makarova on Margaret Court Arena.
Keys was struggling with a thigh injury in the third set, but the nature of her exit from the tournament will probably hurt more after she hobbled out of the tournament clearly unable to run freely.
Keys had comfortably won the opening set but was broken by the Chinese in the third game of the second and immediately took a medical time out for treatment to what appeared to be a left leg injury.
US Open
Gauff clinches place in quarter-finals with brilliant display to see off Zhang
04/09/2022 AT 22:10
Keys then found it difficult to move around the court and the 27-year-old Zhang used that to her advantage to make the American chase the ball and send it to a decider.
Keys, a semi-finalist last year, looked on the verge of retiring several times in the deciding set but battled on grimly despite being in obvious pain.
The 133rd-ranked Zhang struggled to control her nerves in the decider, but eventually held it together to set up a quarter-final against unseeded Briton Johanna Konta.
The last qualifier to reach the Australian Open quarter-finals was Mexico's Angelica Gavaldon in 1990.
"I was very lucky today," a smiling Zhang said in an on-court interview.

China's Zhang Shuai reacts during her fourth round match against Madison Keys of the U.S. at the Australian Open tennis tournament at Melbourne Park, Australia, January 25, 2016.

Image credit: Reuters

US Open
'Going to be a great player' - Gauff's fine run continues as she eases past Keys
02/09/2022 AT 21:42
WTA Cincinnati
Swiatek sent home by dominant Keys, who beats a world No. 1 for the first time
18/08/2022 AT 20:07