Williams had 40 winners and 40 unforced errors and won the final four games of the match after trailing 3-2.
"It was so frustrating," Williams said. "But I feel like I got my focus more in that second set and toward the end of the third because I'm just a competitor. If things get closer, then I think my better tennis is going to come."
Williams ended her 15-year boycott of the event last year, when she lost in the second round.
Elsewhere on the women's side, No. 2 seed Angelique Kerber lost to 14th-seeded Elena Vesnina 6-3, 6-3 in the fourth round. Kerber is assured of retaking the No. 1 ranking from injured Serena Williams next week.
In other women's matches, No. 3 seed Karolina Pliskova advanced when 15th-seeded Timea Bacsinszky retired trailing 5-1 in the first set; Garbine Muguruza defeated No. 10 Elina Svitolina 7-6 (5), 1-6, 6-0; No. 19 Anastasia Pavlyuchenkova outlasted No. 5 Dominika Cibulkova 6-4, 3-6, 6-3; and No. 8 Svetlana Kuznetsova beat 21st-seeded Caroline Garcia 6-1, 6-4.
The Associated Press contributed to this report.