Caroline Wozniacki celebrates winning the match against Ukraine's Dayana Yastremska in Melbourne on Wednesday. Reuters
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 her sixth match point to reach round three.
She plays Ons Jabeur of Tunisia on Friday.
"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.
Now ranked 36, 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 at the sixth attempt, the young Ukrainian looping a forehand long.
Tribute to Dad
The Dane, who says that a major reason for retiring was to start a family with her husband and former NBA star David Lee, admitted that she feared at the beginning that Yastremska would blow her away.
"She came out swinging... and everything was going in, even balls that I don't think she knew were possible to hit it that way," said Wozniacki, who has won 30 WTA titles in a professional tennis career going back to 2005.
"I was just thinking to myself: it surely can't continue. If it's going to continue, then there is not much I can do."
Wozniacki, who began playing tennis aged seven, is coached by her father Piotr, a former professional footballer.
Asked what the best decision had been in her career, she said: "I think sticking with my dad and that partnership, I think, has made me the player that I am today.
"I definitely wouldn't have been where I am today if it wasn't for him because the trust that was there between us and just the journey was amazing."
Unseeded 15-year-old Coco Gauff said she was in disbelief after beating reigning champion Naomi Osaka in straight sets in a major upset at the Australian Open on Friday.
Caroline Wozniacki's glittering tennis career ended in tears at the Australian Open on Friday when she was dumped out by lower-ranked Ons Jabeur of Tunisia.
"I called her right after the match just to tell her that everything's fine, I won, she can just relax now," a beaming Sofia Kenin told reporters, glass of champagne in hand, referring to mother Lena.
"She's been really stressed at home, very superstitious.
Top seed Novak Djokovic and second seed Stefanos Tsitsipas on Wednesday kept on course for a showdown in Saturday’s final of the Dubai Duty Free Tennis Championships.
Multan Sultans beat Peshawar Zalmi by six wickets in a Pakistan Super League held at the Multan Cricket Stadium on Wednesday. Chasing 124, they completed
Avishka Fernando and Kusal Mendis hit centuries as Sri Lank thrashed the West Indies by 161 runs in the second one-day international to clinch the series on Wednesday.