Gauff, who made a remarkable run to the fourth round at Wimbledon before falling to Halep, defeated Hungarian qualifier Timea Babos 6-2, 4-6, 6-4 to become the youngest player in the last 32 at a US Open since Anna Kournikova in 1996.
"It has been amazing. I'm just so happy to get through," Gauff said as chants of her name rang out around Louis Armstrong Stadium.
"I had to dig really deep today. I'm just proud of the way I fought and I'm glad it was all worth it in the end."
Three-time US Open champion Nadal advanced without striking a ball when injury-plagued Australian Thanasi Kokkinakis pulled out of their scheduled evening tie on Arthur Ashe with a right shoulder problem.
The Spanish 18-time Grand Slam winner will meet South Korean qualifier Chung Hyeon for a spot in the last 16.
His path to a fourth title, already helped with "Big Three" rivals Novak Djokovic and Roger Federer on the opposite side of the draw, cleared further having already seen four top-10 rivals dumped out in the first round.
Alexander Zverev, the sixth seed, is the highest-ranked player remaining on his side of the draw, as the German survived a second successive five-set marathon by outlasting American Frances Tiafoe 6-3, 3-6, 6-2, 2-6, 6-3 to equal his best US Open run.
Top seed Osaka proved too strong for 53rd-ranked Magda Linette of Poland, sweeping to a 6-2, 6-4 victory.
"I feel like I had my moments where I played really well," Osaka said. "I think the main thing for me was that I was able to adjust whenever I figured out something was going wrong, so I think I'm heading in the right direction."
Among the celebrities watching her match at Louis Armstrong Stadium were basketball legend Kobe Bryant and former NFL quarterback Colin Kaepernick, whose kneeling protest became a national symbol for champions of social justice and racial equality.
"I'm really grateful they came out," Osaka said. "It's really cool. I honestly just wanted to finish as fast as possible because I didn't want them to be out in the sun too long."
Men's fifth seed Daniil Medvedev, coming off a maiden Masters title in Cincinnati, was struck down by cramp during a 6-3, 7-5, 5-7, 6-3 win over Bolivia's Hugo Dellien.