Sharapova hit 23 winners, one more than Azarenka, and had 10 fewer unforced errors than Azarenka's 37 to even their all-time series at seven wins apiece.
Top-ranked Novak Djokovic beat Albert Ramos-Vinolas 7-5, 6-3, rallying from a 3-1 deficit in the first set and earning a crucial break with a forehand winner go up 5-3 in the second set.
''I managed to play the right shots at the right time in the important moments, and I managed to sneak through in straight sets,'' Djokovic said on court.
Azarenka fought off four match points on her serve in the eighth game to hold trailing 5-3. They dueled through five deuces until Azarenka fired a big serve to keep herself in the match.
Sharapova took a 40-15 lead to set up her fifth match point, but netted a forehand. She converted on her sixth one with a dipping crosscourt backhand that Azarenka couldn't return near the net.
''I was aggressive, even though I was missing some shots, missing quite long and wide at times, I just kept going for it,'' Sharapova said. ''Kept being aggressive and staying in there.''
She showed off an array of drop shots, including one that led to her breaking Azarenka to end the first set. Sharapova joked that it's taken her 24 of her 27 years to work on drop shots, something she never did while learning the game.
''These are little things that I think I have incorporated much more in my game,'' she said.
Sharapova, a two-time champion at Indian Wells, will meet defending champion Flavia Pennetta in the fourth round. Seeded 15th, Pennetta beat Sam Stosur 6-4, 6-2 on an outside court.
Azarenka, who beat Sharapova for the title here in 2012, is just starting to return to form after a left foot injury limited her to nine tournaments last year and dropped her ranking to 32nd. The two-time Australian Open champion led 4-3 in the first set before Sharapova won the final three games.
''I'm just really disappointed because when you create opportunities and you don't take them, that's pretty frustrating,'' Azarenka said. ''I've got to step it up with finishing those games and really taking my chances.''
Two more former Indian Wells champions and top-ranked players went out in the third round. Fourth-seeded Caroline Wozniacki lost to 31st-seeded Belinda Bencic, 6-4, 6-4, and fifth-seeded Ana Ivanovic lost to 25th-seeded Caroline Garcia 6-2, 5-7, 6-2.
Bencic earned her first win over a top-five player and at 18 became the youngest player to reach the fourth round this year. Last year in Istanbul, Bencic failed to win a game off Wozniacki.
In other women's matches, No. 6 seed Eugenie Bouchard beat CoCo Vandeweghe 6-3, 6-2; Sabine Lisicki beat No. 11 seed Sara Errani, 6-4, 6-2; and qualifier Lesia Tsurenko defeated 20th-seeded Alize Cornet, 7-5, 1-6, 6-2.
Andy Murray outlasted Philipp Kohlschreiber 6-1, 3-6, 6-1 in a nearly two-hour baseline slugfest under a hot sun. Murray earned the only two breaks of the third set and closed out the win when Kohlschreiber's forehand went wide, one of 35 unforced errors by the German. The temperature topped 90 degrees (32 Celsius), unusually warm for this time of year.
Cool mornings, hot afternoons and warm evenings have made for changing court conditions and ball speed in the desert, and Murray was affected by them.
''When you are playing in those matches during the heat of the day, you need to trust your shots. You need to go after them, because if you back off and try and sort of guide the ball in these conditions, it doesn't work,'' he said. ''During the day it's ridiculous how high the balls bounce and how quick they move through the air and jump off the court.''
Murray moved on to a fourth-round match against Adrian Mannarino, who beat 14th-seeded Ernests Gulbis, 6-4, 6-4.
Fifth-seeded Kei Nishikori was stretched to three sets before overcoming Fernando Verdasco, 6-7 (8), 6-1, 6-4. Nishikori double-faulted twice in the final game before advancing to the fourth round for the first time in his seventh appearance at Indian Wells.
John Isner beat 18th-seeded Kevin Anderson, 7-6 (8), 6-2, setting up a fourth-round match against Djokovic. Isner has lost just 12 points on his big serve in his first two matches.
''He's one of the best servers in the history of the game,'' Djokovic said. ''He's 6-foot-10, and he can hit any angle he wants.''
Jelena Jankovic, who won here in 2010 and spent 18 weeks at No. 1 in the world, outlasted Madison Keys, 5-7, 6-4, 6-3 despite the Serb having just 13 winners and 42 unforced errors.
Jankovic is coming off a back injury and torn muscle in Doha, which hampered her practice schedule.
Keys, a 20-year-old American coached by former top-ranked Lindsay Davenport, had her chances to take control, leading 3-1 in the final set. She hit 39 winners, but came undone with a whopping 64 unforced errors.