It began with mild discomfort. Soon, it worsened. Later, it was extreme nausea.

Madison Keys even needed a medical timeout midway through the second set. But the illness — and No. 20 Sofia Kenin — wouldn’t stop the 10th-seeded American from earning a fifth straight fourth-round berth at the U.S. Open.

Keys responded after getting seen by a doctor by winning four of the next five games to prevail, 6-3, 7-5, at Arthur Ashe Stadium on Friday night advance to a Round of 16 meeting with fifth-seeded Ukrainian Elina Svitolina.

“It would’ve been a lot trickier if I had a third set,” the 2017 U.S. Open finalist said in her on-court interview. “This was definitely a test.”

Keys passed it, mostly because of her ability to save her serve, staving off eight break points, to go along with a 26-9 edge in winners.

The two biggest ones came in her final service game, down 15-40 and up 6-5 in the set, only to rally to victory with a forehand cross-court

winner to knock off the American Kenin.

“It was super weird,” Keys said. “Just kind of in the middle of the first set, all of a sudden started feeling not perfect. The end of the first wasn’t feeling amazing. But luckily I was able to get through it. I feel like I played some good points in some big moments when I needed to.”

Keys declined to offer further insight into what was bothering her, saying she “won’t give you all of the gory details.” But retiring never was a consideration. Neither, in her mind, is taking it easy Saturday. Keys fully expects her condition to improve so she can prepare for Svitolina.

“It better,” she said.

Now owning a career-best nine straight match victories after winning at Cincinnati, Keys is hoping to continue another strong tournament in Queens. Two years ago she reached the final. Last year, it was the semifinals.

“I love this court,” she said of playing at Ashe. “Some of the absolute best moments of my career have happened on this court.”