Williams cruised through the opening set, securing both of her break points as Azarenka struggled to stay in contention.
But the Belorusian rallied in the second set and took a 4-1 lead following a string of unforced errors from her opponent.
Wiliams showed her mettle to save seven break points in the next game to avoid a third break of her serve but Azarenka held before finally breaking to level the match.
Azarenka established a 4-2 lead in the deciding set but Williams hit straight back and broke again to lead 5-4.
The American served for the match but fell 15-40 behind after netting a forehand and was broken as Azarenka produced a stunning return in at her feet.
The second seed held serve and had won eight out of the last nine points, only for Williams to serve out to set up the crucial tie-break.
Azarenka opened up a 3-1 lead and restored her cushion after Williams pulled back the mini-break.
From 4-2 at the change of ends, though, Azarenka fell 5-4 behind after losing successive service points.
That left Williams needing to claim her two service points to take the title but she somehow missed on the first after opening up the court with a drop shot before double-faulting on the second.
Azarenka also spurned the chance to close out the match when she sent a backhand long on championship point.
But she set up another with a deft volley and Williams then put a forehand into the net as Azarenka claimed the crown.
"Obviously, it was a big win. It was a great match," said Azarenka.
"I am really pleased with the way I pulled it out. It was a great battle."
Meanwhile, Williams paid tribute to her opponent after the match.
"I'm number one, she's number two, so we have that rivalry, which makes it even more so exciting," she said.
"I personally was thinking it is a good rivalry and it's good to have someone out there that can play hard and fight so tough.
"She's a great player. There's a reason why she's winning grand slams and doing so well."
"There were no giveaways. It was pure fight."