The world number one came through 3-6, 6-4, 6-2 in two hours and three minutes to reach round four.
Tempers frayed at the end of the second set, with Azarenka waving away Williams’s explanation over a disputed line call.
“I was really down and out and I just really zeroed in,” said Williams. “I focused and really wanted to win that.”
Asked about her argument with Azarenka, the American added: “We talked about this a long time ago.
“We said, ‘we’re going to leave everything on the court, we’re going to give 500 per cent and when we’re off the court, we’ll be really cool’.
“I love that relationship, because she’s a really fun girl. It’s not often that you can have that with someone. So it’s cool.”
Williams will continue her bid to win a third French Open and 20th Grand Slam title against compatriot Sloane Stephens in the last 16.
It is two years since Azarenka had her best run in Paris, reaching the semi-finals, before injury decimated her 2014 and led to a fall down the rankings.
She had shown earlier this month that her best form was back when she earned three match points against Williams in Madrid, only to blow her chance.
The Belarusian, seeded 27th, was in a strong position once again at a set and a break up, but let a 4-2 lead slip in the second as the top seed came roaring back.
Azarenka saved three set points but reacted angrily on the fourth when her shot was incorrectly called long, and the umpire ordered they replay the point.
Williams insisted she had been distracted by the call but Azarenka, up at the net in discussion with the umpire, angrily waved away the American.
She duly lost the following point and headed straight for a bathroom break to cool down ahead of the final set.
Azarenka came out firing again with an early break but the increasingly pumped-up Williams was not to be denied, racing through six straight games and sealing victory with a brilliant forehand winner.
After the match, Azarenka called for a review system to deal with disputed points.
“I’m not saying this as an excuse,” she said. “But in that moment, if you don’t have a review like that, it’s causing a lot of problems.”
And she played down the row with Williams, adding: “We don’t have any air to clear. But I gave her a pair of my shorts because she really liked them. True story.”