The 25-year-old Austrian, ranked eighth in the world, had fallen in two prior Masters finals, both in Madrid.
But he rallied for a third career win over Federer in five meetings, his first over the Swiss on hard courts.
Thiem earned the crucial break in the 11th game of the final set, connecting on two sharply angled passing winners to give himself a break point which he converted with a stinging forehand winner.
He sealed the match after two hours and two minutes when Federer's backhand found the net and will now return to a career-high ranking of fourth in the world.
It was the second year in a row that Federer was denied in the Indian Wells final. In 2018 he missed out on three championship points as he fell to Argentina's Juan Martin del Potro in the title match.
Federer, fresh off a remarkable 100th career title in Dubai, remains tied with Novak Djokovic for the most Indian Wells victories with five.
"I think it's not my right to congratulate you, you have 88 more titles than me," Thiem told Federer as he accepted the trophy.
He's the first Austrian to win a Masters 1000 title since Thomas Muster in Miami in 1997.
But he was under attack early, saving three break points before succumbing on a fourth in the second game as Federer raced to a 3-0 lead.
Federer led 4-1 before Thiem clawed a break back, but Federer responded with another hard-won break for a 5-3 lead and captured the set with a service winner.
Coming into the contest Federer had won 20 straight finals when claiming the opening set.
But Thiem was not about to go quietly, breaking Federer for a 3-1 lead as the Swiss suddenly couldn't put a first serve in.
An authoritative hold put Thiem up 4-1 and on the way to forcing the third set.
"It's been a great week for me, even though it didn't work out," Federer said. "Congratulations to Dominic -- wonderful week and great play at the end. You deserved it."