The 29-year-old former world number one roared back in both sets to defeat 23rd-seeded Dayana Yastremska of Ukraine 7-5, 7-5.
Neil Diamond's hit "Sweet Caroline" rang around a blustery Margaret Court Arena after the Dane nailed the sixth match point to reach round three in blustery Melbourne.
She plays Ons Jabeur of Tunisia.
Immaculate Federer reaches Australian Open second round in style
"It's a little bit emotional for me," said Wozniacki, the 2018 Australian Open winner who announced in December that this would be her final tournament.
"The crowd really got behind me so that was so special. Thank you everyone for coming out today, it really means a lot to me," she added, fighting back tears.
The 19-year-old Yastremska, beaten by world number one Ashleigh Barty in last week's final in Adelaide, threatened to put a swift end to Wozniacki's career.
But having been 5-1 down in the first set, Wozniacki -- who suffers with rheumatoid arthritis, which causes fatigue and joint pain -- fought back to claim the set in 53 tough minutes.
Fuming Shapovalov slams 'terrible call' in Australian Open upset
Now ranked 36th, having ended 2010 and 2011 at number one in the world, Wozniacki was similarly quickly down 3-0 in the second set.
But once again she battled back to make it 4-4, then held her own serve to lead 5-4 and within touching distance of round three.
Yastremska then required a medical timeout for what appeared to be a left thigh problem, and returned to court with heavy strapping.
She saved five match points, but with the crowd firmly behind her, Wozniacki would not be denied.
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ