Serena Williams drops the opening set to Caty McNally but comes back strong to edge the young American challenger and move on to the third round. (2:09)

NEW YORK -- Serena Williams avoided what would have been her earliest loss in 19 appearances at the US Open.

Williams came back from a set down in the second round -- the first time she had ever lost a set in the round of 64 -- at Flushing Meadows to beat 17-year-old American Caty McNally 5-7, 6-3, 6-1 in a match that ended as Wednesday turned into Thursday.

Williams didn't drop a single point on her serve in the decisive third set and won 24 of the 29 total points played. She did not face a break point over the final two sets.

"You can't win tournaments making that many errors,'' Williams said. "I knew I had to play better, and I knew I could.''

And so she did.

"Obviously, she's going to pick up her level. I knew that was going to happen,'' McNally said. "Next time, I just have to raise my level with hers.''

Williams improved to 38-0 in the first two rounds at Flushing Meadows. The only time she was beaten as early as even the third round in New York was in her tournament debut all way back in 1998 -- when she was just 16 herself.

The following year, Williams won the first of her six US Open championships. McNally hadn't even been born yet.

Now Williams owns 23 Grand Slam singles titles in all, and she showed off why while powering her way through a deficit, taking 16 of the final set's initial 17 points.

McNally had never won a match at any major tournament until Monday. She is ranked 121st and received a wild-card invitation from the U.S. Tennis Association for singles and for doubles, the latter with 15-year-old sensation Coco Gauff.

play 1:17 Serena spaces out during interview after surviving McNally Serena Williams rallies back to defeat Catherine McNally, and expresses how tired she is and the mistakes she made during her postmatch interview.

Williams never looked comfortable early as McNally charged the net, serving-and-volleying and looking like someone who belonged on this stage.

The Arthur Ashe Stadium crowd, made louder than usual under the retractable roof that was closed all day because of showers, alternated whom it was pulling for, more than happy to cheer for either woman representing the United States at the country's Grand Slam tournament.

"She's young. It's her first time in a stage like this and only her second Grand Slam, so I think there's a lot to gain from it,'' said Lynn Nabors-McNally, Caty's mother, who also helps coach her. "It's a great steppingstone to a lot of things.''

So there was McNally, almost strutting to the sideline while waving her arms, trying to get the spectators to offer even more noise and more applause after she pulled out the opening set in impressive fashion. First, McNally converted her only break point of the match to lead 6-5. Then, she served out the set despite falling behind love-40, erasing three break points and hitting a 103 mph service winner to seal it -- and implored the fans to get loud.

Best Win Percentage After Losing 1st Set In Majors Serena Williams is the only woman in the Open era with a winning record after dropping the first set in a major. Women in Open Era Win pct. Record Serena Williams .512 42-40 Chris Evert .500 28-28 Monica Seles .486 18-19 Steffi Graf .469 23-26 >> Min. 20 matches

They obliged.

"I knew I was playing against the greatest of all time. ... I walked out there and I had the chills,'' McNally said. "Super happy just to get a set from her. That's something that not very many people do.''

And for a bit of the second set, too, McNally stayed with Williams.

But Williams started to pull away, in part by dispensing with the serves out wide that McNally was handling well and in part by reducing her mistakes from 15 unforced errors in the first set to 11 in the second to two in the third.

"I want to be able to win matches where I'm not playing my best and then play players who are playing great and be able to come through, and I need to be tested, I guess," Williams said. "Honestly, I'd rather not be tested and win every match. That doesn't happen, so it's important for me to have those really rough, rowdy matches -- that helps a lot."

ESPN Stats & Information and The Associated Press contributed to this report.