Williams, 38, raced to a 5-2 in the opening set before Sakkari drew level but the American raised her game again to take the early advantage in the rain-delayed contest.
Williams trailed 3-1 in the second set before reeling off four games in a row and was serving for the match when things began to fall apart.
World number 21 Sakkari dragged the set to a tie-breaker before levelling the contest at 1-1, then surged to a 5-0 lead in the decider and completed the upset win on her eighth match point with a powerful forehand.
Sakkari said she did not play well but was delighted with the victory over the third seed.
“I knew it was going to be an ugly match from my side but I’m extremely happy with the result,” Sakkari said.
“She’s a role model for me and many others. What she has achieved in our sport is unique and I don’t know if anyone else is going to do it again.”
Sakkari next faces Briton Johanna Konta, who got past Vera Zvonareva 6-4 6-2.
Earlier, Naomi Osaka put on a solid serving performance to beat Dayana Yastremska 6-3 6-1 and advance to the quarter-finals where she will face Anett Kontaveit, who beat Marie Bouzkova 6-3 6-3.
Osaka fired eight aces to zero for Yastremska and needed just over an hour to dispatch the 20-year-old Ukrainian.
“The serve is a really important part of my game and I just need to tune it up,” said fourth seed Osaka, who was playing in just her second WTA singles match since the Tour resumed.
“The percentage still wasn’t that high today so hopefully as I play more matches it’ll get better.”
Former world number one Victoria Azarenka improved her record against Alize Cornet to 7-0 with a 6-4 7-5 win to advance to the quarter-finals, where the Belarusian will meet Ons Jabeur, who beat Christina McHale 6-3 6-0.
The tournament, the final tune-up before the U.S. Open Grand Slam, is being played at Flushing Meadows in New York instead of Cincinnati due to the COVID-19 pandemic.