The gunman who killed three people at a Northern California food festival Sunday night turned and fired his “AK-47-type assault rifle” at responding officers before being fatally wounded, police say, as they continue investigating what may have led Santino William Legan to carry out the horrific assault.

Gilroy Chief of Police Scot Smithee told reporters Monday afternoon the attack at the Gilroy Garlic Festival resulted in the deaths of a male in his 20s, a 13-year-old female and a 6-year-old.

“Despite the fact that they were outgunned with their handguns against a rifle, those three officers were able to fatally wound that suspect,” Smithee said, describing how officers among those already at the event to provide security engaged the gunman less than a minute after the first shots rang out.

“It could have gotten so much worse, so fast,” he added.

WITNESSES RECALL CHAOTIC SCENE AS SHOTS RANG OUT

Police believe Legan legally purchased the rifle in Nevada on July 9 before returning to California with it at some point. A motive for the shooting has yet to be determined.

“Mass gun violence is an epidemic in the United States yet one can never imagine such a thing would happen here in our beautiful community,” Gilroy Mayor Roland Volasco said.

Volasco also hailed police for their quick response, saying the officers “undoubtedly saved many lives by putting their own lives in danger.

“It takes remarkable bravery to run to a shooting when the natural reaction for all of us is to run away,” he added.

Smithee said the gunman gained access to the festival by cutting through a fence near a creek area. He said some witnesses reported a second suspect, but police could not immediately confirm those reports and it was unclear if that person also had a weapon or may have been providing some support to the shooter.

The band TinMan was just starting an encore at the festival when shots rang out.

Singer Jack van Breen said he saw a man wearing a green shirt and grayish handkerchief around his neck fire into the food area with what looked like an assault rifle. Van Breen and other members of the band then dove under the stage.

During the chaos, Van Breen says he heard someone shout: "Why are you doing this? "and the reply was: "because I'm really angry. "

2020 DEMOCRAT PRESIDENTIAL CANDIDATES RESPOND TO SHOOTING

President Trump, speaking about the shooting Monday, said a "wicked murderer opened fire and killed three innocent citizens including a young child."

"We grieve for their families and we ask that God will comfort them with his overflowing mercy and grace," he added. "We are praying for those who are recovering right now in the hospital, some very, very serious injuries. We thank the brave members of law enforcement -- they never let us down -- who swiftly killed the shooter."

The Santa Clara Medical Examiner identified one of the victims as 6-year-old Stephen Romero, of San Jose.

"He had his whole life to live," Alberto Romero, the boy's father, told NBC Bay Area.

Ryan Wallace, a witness, told the channel that he watched the gunman -- who was almost dressed like a police officer -- raise his gun up and started to “spray rounds.” The gunman walked through the crowd, he said.

“He wanted to get stuff done,” he said. “It was horrifying.”

Personal videos posted to Twitter appeared to show large crowds evacuating the festival. Many witnesses said the shots sounded like fireworks and there initially was confusion over the source of the noise.

CLICK HERE TO GET THE FOX NEWS APP

One witness told KTVU that he heard what he believed was 30 rounds. Some witnesses said the gunman was in army fatigues.

Natalie Martinez, a Gilroy resident, told the Mercury News that she had gone to get food and separated from her two daughters. "I ran to find the girls and we basically ran into each other. I thought, 'We're open prey.' It was awful."

The Associated Press contributed to this report