Williams fell into a 0-40 hole in the fifth game of the second set and Wang delivered a forehand victor to take a 3-2 lead.
But it was the Chinese No.1 who played the bigger points better in the final set to win 6-4 6-7 (2-7) 7-5.
The Chinese player's form deserted her as she served for the match at 5-4, allowing Williams to break back with a superb forehand victor at the end of a 24-shot rally.
Williams, 38, was the bookies' favourite to win a record-equalling 24th Major at Melbourne Park but she came unstuck against a determined Wang, who won 6-4, 6/7 (2/7), 7-5 - after taking only one game the last time they met.
Williams was looking to break Margaret Court's Grand Slam tally of 24 but she will now have to wait.
Wozniacki will face Ons Jabeur in the next round after the Tunisian beat Caroline Garcia of France 1-6, 6-2, 6-3. "I thought, 'OK, now finish this off.' I honestly didn't think I was going to lose that match".
He gave her a kiss on the cheek by way of an apology, then continued on his way to a 6-3 7-6 (7-4) 6-1 victory.
Speaking to media after her second round win on Wednesday, Wang said that she would be studying Williams' form and looking to improve upon the result of their previous meeting. "She served well. I didn't return like Serena. I think about my practice tomorrow, try to follow up the level of tennis that I played in the third set", he said.
Considered widely as the best returner of first serves and baseline player among contemporaries, Friday's match at the Rod Laver Arena showed that Djokovic was also right up there with the best servers in the game. The 32-year-old dropped a set and won in the Australian Open first round for the first time in his career by getting past Jan-Lennard Struff in four. I'm very happy she is good. Serving for the set, Wang won a full-blooded rally to bring up set point and then sealed it to go one set up - a far cry from their last meeting in NY.
Williams is not one of those, and she will hold high hopes for Wimbledon and the US Open having reached the final at both events in 2018 and 2019.
The Tianjin native broke Williams again in the second set but was denied a quick kill by the American's spirit and backhand.