The two-and-a-half-hour epic featured multiple momentum shifts after Azarenka, the second seed from Belarus, began the afternoon with two double faults to lose the opening set in under 30 minutes.
She managed to steady herself and held on to beat the top-seeded Williams for only the third time in 15 matches. It was her second victory over the American this year, after a triumph in the final at Doha.
"What doesn't kill you makes you stronger," said Azarenka who earned her 17th career title and first in Cincinnati. "It was a tough match and we both fought really hard. It was an incredible week for me.
"I'm feeling very good. Obviously, it's a big win. It was a great match. I'm really, really pleased with the way I pulled it out. It was a great battle."
Azarenka had played sporadically over the past months due to injuries suffered at both Wimbledon and this month in California. The Belarussian was competing in only her 10th event of an injury-hit season.
"I'm really excited to be back playing," said the former world number one. "The last month was really tough."
Azarenka lost a second set in which Williams saved eight break points in the sixth game. With the sets level, the third went to a decider as the pair traded four breaks in five games.
Williams double-faulted for a match point in the tiebreaker, but Azarenka gave it back with an error. Azarenka then shipped over a winner for a second winning chance and followed through for the win a point later.
Williams had been trying for two major hardcourt titles in a row after winning Montreal last weekend.
"She played really aggressive in the last two sets, which really changed momentum," said Williams. "She's a great player. There's a reason why she's winning Grand Slams and doing so well.
"I have tough matches, particularly against her," Williams said. "We go against each other really tough. It's a good rivalry. I'm number one, she's number two. So we have that rivalry which consists of meeting in the final, which makes it even more so exciting."
Between them, Williams and Azarenka have claimed five of the last seven Grand Slam singles titles dating to the 2012 Australian Open.
Williams beat her rival in the US Open final a year ago.
Photos: Shah Rukh Khan, Shweta Bachchan at Karan Johar's book launch
Photos: Sunny Deol with sons Karan and Rajvir at Mumbai airport
Photos: 10 beautiful moments that capture winter around the world
Photos: Karisma Kapoor, Preity Zinta, Shraddha Kapoor at Mumbai airport
Spotted: Anushka Sharma and Diljit Dosanjh at Mumbai studio