Wozniacki found herself on the brink of defeat as she trailed 4-2 in the final set, but the Dane roared back to claim the last four games to seal the victory.
The 22-year-old Barty was ultimately let down by her groundstrokes in crucial stages of decider as she finished with 54 unforced errors for the match.
Wozniacki will next face former French Open semi-finalist Kiki Bertens, who stunned 15th seed Anastasija Sevastova 6-1 6-4 in the second round.
'She is a billion-dollar girl' - How Raducanu has the world at her feet
Former world number one Maria Sharapova's revival on clay is gathering pace as she overcame a tense opening set to beat Romania's Irina-Camelia Begu 7-5 6-1.
The 31-year-old Russian, who entered the tournament on the back of four consecutive defeats, rallied from 3-1 down before snatching the opening set with a ferocious forehand.
With momentum on her side, Sharapova won 20 of the last 22 points to secure a spot in the last-16.
"Although I didn't play at my best level in the first set, I pulled it through," the five-time grand slam champion told a news conference.
"I played some really tough points. I hung in there especially in that final game. Then I really set up a good opportunity for me to step up.
"I thought I did a really good job of that, especially in the last six games. I was very aggressive, played deep, returned a lot better. That will certainly help me moving forward."
Unseeded Sharapova will next face last year's finalist Kristina Mladenovic, who edged China's Zhang Shuai 6-4 4-6 6-3.
Tennis stars fill red carpet at Met Gala as Raducanu celebrates US Open title
'Sharapova is my idol' - Get to know Paula Badosa at Roland Garros