Murray raced into a 3-0 lead but was pegged back to 4-4 and, after failing to take a set point on the Alcaraz serve at 5-4, lost the opening set.
Murray, 34, broke twice in the decider on the way to taking a captivating match against the 18-year-old in three hours and three minutes.
The victory will provide Murray, who is 121st in the men’s rankings, with plenty of encouragement as he continues his latest comeback after four disrupted years following a major hip injury.
He will play third seed Alexander Zverev in the next round, after the German defeated American Jenson Brooksby 6-4 3-6 6-1.
“It was a brutal match, really tough conditions,” Murray told Amazon. “The way I fought after losing the first set was great because I feel I should have won that first set.
“I created lots of chances but didn’t take them. It would’ve been easy to let that slip away but I kept fighting and finished it well.”
Alcaraz, ranked 38th in the world, beat Stefanos Tsitsipas at the US Open in September and looked like he was ready to impose himself on the match after taking a 67-minute first set.
But he could not shake off a resilient Murray, who came back from 15-40 down on his serve in the third game of the second set before audaciously taking it with an underarm ace.
“The courts are painfully slow here,” added Murray. “I was thinking about using it [the underarm serve] again in the third set.
“He changed his return position towards the end of the first, he started going further back and I was like ‘just give it a go and see’
“I used it, it worked well and maybe I’ll use it again in the future if guys are going to stand that far back and they’re going to make courts like this.”
Murray went on to level the match and, having broken Alcaraz in the first game of the deciding set, found himself 15-40 down on his serve again, only to fend off his rival in a game of 10 minutes 32 seconds to consolidate his break.
Murray then broke Alcaraz once again and secured an impressive win as he served and volleyed to take match point.
Elsewhere in the men’s draw, there was an upset as Spain’s Albert Ramos-Vinolas, ranked 48th, shocked Canadian seventh seed Felix Auger-Aliassime in straight sets.
Greece’s second seed Tsitsipas reached the third round at Indian Wells for the first time as he beat Spaniard Pedro Martinez 6-2 6-4 to set up a clash with Fabio Fognini.
In the women’s draw, Victoria Azarenka defeated seventh seed Petra Kvitova 7-5 6-4 and will take on fellow Belarusian Aliaksandra Sasnovich, who beat 11th seed Simona Halep by the same score, in the fourth round.
Polish second seed Iga Swiatek breezed past Russian Veronika Kudermetova, dropping just one game, but Ukrainian fourth seed Elina Svitolina was forced to work much harder, coming back from a set down to beat Sorana Cirstea 4-6 6-4 7-6 (7-3).