Williams, 31, had already done enough this week to confirm she will replace Azarenka as world number one on Monday.
But Azarenka ended a run of nine consecutive defeats against Williams as she beat her for only the second time in 12 attempts.
“I just wanted to fight and give myself every opportunity to get back,” said Azarenka.
I told myself, ‘You have to keep it together, you have to do something otherwise Serena’s on a roll and she’s going to bring her A game.’
“I had to really step up my game and I’m glad that I could turn it around, stay tough and focused.”
Williams was unsettled early on, dropping serve with a double fault in game three and complaining to umpire Eva Asderaki that Azarenka was delaying her serve by saying she was not ready to receive.
Azarenka faltered only once in an impressive serving display in the opening set, but that allowed Williams to force the tie-break and earn the first set point.
With the set slipping away, Azarenka boldly took the initiative and moved into the forecourt, drawing an error from Williams who was forced into attempting a forehand pass.
Two points later the 15-time Grand Slam champion hooked a backhand into the tramlines, and Azarenka had the lead she deserved.
Williams broke early in the second but then looked to be struggling with her back after a heavy fall when chasing down a drop shot, but despite some apparent discomfort she managed to hold in a lengthy game at 3-2 and went on to break serve once again as she saw out the set.
If the closing stages of the second saw Williams looking somewhere near her best, it was Azarenka who hit the heights early in the decider as she rediscovered her first serve and backed it up with some clinical hitting.
The Belarusian had led by a break and failed to convert in the third set of the US Open final against Williams last September, but this time she finished the job impressively.
After seeing one match point slip by on the Williams serve, Azarenka closed out the win with a confident hold to extend her unbeaten run in 2013.
“I can’t say that I’m depressed like I am whenever I lose,” said Williams.
“I’m definitely not happy, but I’m number one. It was such a long journey, and after winning Wimbledon and the US Open and the (season-ending) Championships, I thought, ‘I just don’t think I can win anymore. I don’t know what it takes to be number one.’
“So it was awesome to come here and achieve that goal.”