The last countrywoman to beat her was big sister Venus in Montreal in 2014.
Playing on what almost amounts to her home court, Williams was not in top form, making more than 40 unforced errors, but she finally wore down McHale in the third set.
"She's clearly capable of playing great tennis. She showed it today," a relieved Williams, speaking of her opponent, told Tennis Channel in an on-court interview.
"Miami is such a special place to me. I live so close to here," continued the 21-times grand slam singles champion, who resides in nearby Palm Beach Gardens.
The hard-fought victory came only days after Williams was beaten by Victoria Azarenka in the Indian Wells final in California on Sunday.
In her only other tournament appearance this year, Williams lost the Australian Open final to Angelique Kerber in January.
In other women's second-round Miami matches, third seed Agnieszka Radwanska advanced with a 6-0 6-1 cakewalk over Frenchwoman Alize Cornet.
"I'm just very happy with that win, maybe the score was not showing everything that was happening on the court," the Pole said.
"But I think it was a great start and a couple of tight games at the beginning of both sets was the key."
Fifth seed Simona Halep also moved into the third round by beating Daria Kasatkina 6-3 7-5.
The biggest casualty was 11th-seeded Lucie Safarova of the Czech Republic, who fell to Yanina Wickmayer of Belgium 6-2 6-3.
(Reporting by Andrew Both in Cary, North Carolina; Editing by Larry Fine/Patrick Johnston)