The home of 19-year-old Santino William Legan, gunman of a mass shooting at the Gilroy Garlic Festival

The teenager who opened fire with an assault rifle at a weekend food festival in Northern California, killing three people, died from a self-inflicted gunshot wound to the head, autopsy results announced on Friday found.

Police had originally asserted that the gunman, Santino William Legan, 19, was shot dead by police officers who were on patrol at Sunday's Gilroy Garlic Festival and confronted Legan when he began his rampage.

Gilroy Police Chief Scot Smithee insisted the three officers who exchanged fire with Legan were still heroes, saying the casualty toll would likely have been higher had they not engaged the gunman as quickly as they did, within seconds after he began shooting.

"In my mind, it changes nothing," Smithee said of the preliminary autopsy results. "The officers still got there fast, they engaged him fast, they drew his fire and they eliminated the threat."

Speaking to reporters on Friday, Smithee said the suspect turned his gunfire from the crowd to the officers as they reached him, and he was struck by "several" shots returned by the police, none of whom was wounded in the exchange.

The gunman initially fell to his knees, then to the ground. But he managed at some point to squeeze off a final round from his gun into his own head, Smithee said.

The autopsy showed specifically that Legan died from a self-inflicted gunshot fired into his mouth, said Cindy Gallego, a spokeswoman for the Santa Clara County coroner's office.

The chief said his understanding was that his officers had not realized at the time that the suspect shot himself.

The precise number of rounds fired by police and the number striking the suspect would be detailed in a full autopsy report, to be made public later, along with toxicology tests, Smithee added.

Three people attending the festival were killed, including a 6-year-old boy and 13-year-old girl, and a dozen others were injured, some seriously.

The violence erupted near the end of an annual decades-old event celebrating produce farmed in the countryside of California's Santa Clara Valley, about 30 miles (48 km) southeast of Silicon Valley.

Police said the gunman opened fire with an "AK47-variant" of an assault-style rifle, which he had purchased legally in Nevada. A shotgun also purchased in Nevada was later found in his car.

Police and FBI investigators believe Legan acted alone but have yet to determine his motive.