The American added to her 2012 Wimbledon and Olympic crowns after being pushed to the limit by the Australian Open champion, who forced the 30-year-old to drop her first set of the tournament.
"I honestly can't believe I won. I was preparing my runner-up speech because she was playing so well," Williams said courtside after the match, which lasted two hours 18 minutes.
"I'm so shocked. It's remarkable."
It was the first time in 17 years that the women's final went the distance in New York, and it ended Azarenka's run of 12 successive victories in matches lasting three sets.