Williams looked supreme in the first set as a New York final rematch against Naomi Osaka beckoned but Azarenka fought back superbly to win 1-6 6-3 6-3.
Williams was not helped by a jarred Achilles early in the deciding set that required heavy strapping, and her quest to equal Margaret Court's record of 24 grand slam singles titles goes on.
Instead it is two-time Australian Open champion Azarenka who will face Osaka – an impressive winner in a superb match against Jennifer Brady, – in a quite remarkable story of resurgence.
The 31-year-old had been a shadow of her former self since her stop-start return from maternity leave in 2017 and had almost been written off as a major contender prior to her victory on the same courts in the Western & Southern Open last month.
A lengthy custody battle with her former partner over their three-year-old son, Leo, kept her away for several spells and took its toll on and off court, while her confidence ebbed away.
This was the former world number one's first slam semi-final since her second consecutive final against Williams in New York in 2013, both of which were high-quality, close affairs but both were won by the American.
In 2012, Azarenka had held a 5-3 lead in the final set, just as she did here, only for Williams to come back.
"I knew it wasn't over at 5-3," said the Belarusian. "I've been there before. Today was going to be different. I was young, my ego was way too big. Now it's a little smaller and the result's coming."
The presence of so many mothers in the draw and in the latter stages of the tournament has been a major talking point, and Azarenka hopes she can encourage other women to aim high.
"Hopefully it inspires women to go after their dreams," she said. "I feel like you can't always identify yourself as just one thing. You have many things you can do in your life.
"Being a parent is the most important thing in my life but I'm a tennis player on the court, I'm a fighter on the court and, when I go after my dreams, inspire my child and I hope that women around the world know they can do anything because being a parent is the toughest thing so once you can balance that you can do anything."
Williams had battled through three-set matches in the previous three rounds but came out firing here, racing into a 4-0 lead.
The turning point came with a stunning return game at 2-2 in the second set from Azarenka and, by the start of the third, it was Williams who was trying to regain a foothold.
She insisted afterwards that the Achilles issue, for which she took a lengthy timeout midway through the second game and was eventually broken, did not affect the outcome and will not prevent her competing at the French Open later this month.
"I started really strong," said Williams. "Then she just kept fighting. She just changed and started playing better and better. Maybe I took a little too much off the gas pedal at some point. She played really well.
"It's obviously disappointing. At the same time, I did what I could today. I feel like other times I've been close and I could have done better. Today I felt like I gave a lot."
The pair are good friends, and Williams paid tribute to Azarenka's resilience saying: "She's had a lot of, I would say, downs in her career. She started on a lot of highs.
"I don't know how she stayed positive, to be honest. That's a good lesson for all of us. No matter what, you just got to keep going. Hopefully she keeps living her dream."
On a day when the nine women who formed the WTA 50 years ago were celebrated at Flushing Meadows, it was fitting that the semi-finals should produce such outstanding matches.
Osaka and Brady battled for more than two hours in a contest of tremendous hitting that sustained its quality throughout.
In the end it was Osaka, the champion here two years ago, who edged it 7-6 (1) 3-6 6-3 to reach her third slam final.
The Japanese fourth seed, who was watched by her rapper boyfriend Cordae, came onto court wearing a mask bearing the name of Philando Castile, a 32-year-old black man who was shot dead by a police officer in 2016.
Osaka's Black Lives Matter activism has garnered lots of attention and appears to have helped her on court.
She said: "I do think it's a very big motivating factor for me just to try to get the names out to as many people as I can. So I'm not sure if that's giving me extra power. Definitely I want more people to talk about it."
Brady has been the breakout star of the tournament and showed she belongs at this level, even if Thursday was Osaka's day.