The American, 31, reeled off 10 games in a row to record an 11th straight win against the world number two.
Sharapova, 25, has still to win in Miami after losing her fifth final.
Williams became only the fourth woman in the modern era to win the same event six times, following Chris Evert, Steffi Graf and Martina Navratilova.
She converted all seven of the break points she created to continue her dominance over Sharapova, whose only two wins in their 14 meetings were in 2004.
Having won her first set against Williams since 2008, Sharapova appeared to be on course to finally end her nine-year barren run against the 15-time major champion.
But after falling 3-2 behind in the second set, Williams surged back, a double-fault from Sharapova handing her a break point in the eighth game which she converted and then served out to force the decider.
The match turned decisively in Williams' favour when Sharapova produced two double-faults to slip 3-0 down, and there was no way back.
"She definitely pushed me," Williams said. "I thought she did a really good job but I felt good and it feels good to have (title) number six."