The gunman who killed three people and injured 13 others at a garlic festival in Gilroy, Calif., this week fatally shot himself after exchanging gunfire with police officers, the authorities said on Friday, updating previous accounts in which they said the officers had killed him.

The Santa Clara County Medical Examiner-Coroner’s office preliminarily ruled his death a suicide.

“In my mind, it changes nothing,” Chief Scot Smithee of the Gilroy Police Department said at a news conference. “The officers still got there fast, they engaged him fast, they drew his fire and they eliminated the threat. Whether he fired that final shot or not, in my mind changes nothing.”

Chief Smithee said that three officers had fired at the gunman, Santino William Legan, 19, on Sunday, striking him multiple times, and that they probably had not even known he had shot himself.

The authorities have not yet identified a motive for the shooting.

“We still do not have a firm grasp of ideology,” John F. Bennett, the F.B.I. special agent in charge in San Francisco, said at a news conference on Thursday. The F.B.I. is combing through social media posts and interviewing the gunman’s family members and friends, Mr. Bennett said.