On her best behaviour but unable to dominate an opponent seven years her junior, Williams showed all her great fighting qualities to survive a ferocious comeback from Azarenka and seal victory after more than two and a quarter hours to become the oldest US Open champion in nearly four decades.
"I honestly can't believe I won," Williams said in a courtside interview. "I was preparing my runner-up speech because she was playing so great. I'm really shocked."
Billed as a clash between the greatest player of her generation and the top player in the world this year, the match lived up to all the hype and more after initially offering only a one-sided romp for Williams.
The American raced through the opening set in just 35 minutes with two service breaks and 16 stunning winners.
But the Belarusian, who won her maiden Grand Slam title at the Australian Open in January, suddenly found a way to penetrate the booming Williams serve, setting the stage for an epic contest in which both players ran themselves to the point of exhaustion.
Azarenka broke Williams for the first time in the opening game of the second set and again to lead 4-1. When the American started to show the first few signs of nerves, Azarenka seized her opportunity and for the first time since 1995, the US Open women's final was forced into a deciding third set.
"I'm just honoured to be standing with such a champion here," Azarenka said.
"I definitely gave it all today. Stepping out of this court today I will have no regrets."
The capacity crowd at the Arthur Ashe Stadium centre court roared with excitement as the two combatants produced some exquisite shotmaking as the stakes rose and the tension increased.
Williams kept her cool, even when she was called for a foot fault, avoiding a repeat of her petulant behaviour at Flushing Meadows in the 2009 semi-final against Kim Clijsters and last year's final with Sam Stosur.
But in the third set, it was Williams who blinked first. Suddenly her golden summer, which included winning a fifth Wimbledon title and two gold medals at the London Olympics, looked like coming to an end.
Azarenka broke and led 5-3, and was two points away from the championship with Williams serving to stay alive.
Williams then provided an emphatic reminder of why she has amassed so many major titles, reeling off the next four games on the trot to seal victory, just a few weeks before her 31st birthday.
Only Australia's Margaret Court, who had already turned 31 when she won her last US Open crown in 1973, won the title at an older age.