The three victims killed in a deadly shooting at a food festival south of San Francisco on Sunday were all young people with much of their lives still ahead of them.

The youngest, Stephen Romero, was described by his grandmother as a kind, happy and playful kid and had just celebrated his sixth birthday in June at Legoland in Southern California.

Also killed was 13-year-old Keyla Salazar from San Jose, seen dressed in pink, wearing a tiara of flowers and smiling as she poses with relatives in photos posted on her aunt's Facebook page.

The oldest victim killed was Trevor Irby, 27, a biology major who graduated in 2017 from Keuka College in upstate New York.

Police on Monday identified Santino William Legan, 19, of California, as the gunman.

They said he cut through a fence at the festival on Sunday evening and shot at people with an assault rifle at the Gilroy Garlic Festival, about 48 kilometres southeast of San Jose, Gilroy police Chief Scot Smithee told reporters. Within a minute of opening fire, Legan was fatally shot by three on-site police officers armed with handguns.

A law enforcement official said investigators believe the gunman used a WASR-10 purchased from Big Mikes Gun and Ammo in Nevada earlier this month. The official was not authorized to discuss an ongoing investigation and spoke to The Associated Press on condition of anonymity.

At least 12 other people were injured. Police had previously said that 15 people were injured. Those victims ranged in age from 12 to 69 years old.

A woman leaves mementos at a makeshift memorial outside the site of the Gilroy Garlic Festival after a mass shooting took place there on Sunday. (Mario Tama/Getty Images)

'We grieve for the families'

U.S. President Donald Trump described the gunman as a "wicked murderer" and asked people to pray for the victims during an event at the White House.

"We grieve for their families, and we ask that God will comfort them with his overflowing mercy and grace," he said.

Smithee said previously a second suspect "was involved in some way — we just don't know in what way." Police later arrested a 20-year-old man who claimed involvement online, but investigators determined he was just trying to get attention.

He said the shooter's motive remains unclear.

Legan appeared to post a photograph from the festival on his Instagram account shortly before the shooting, accompanied by disgruntled captions. The account only appeared to be a few days old, and was deactivated at some point on Monday morning.

Gilroy Police Chief Scot Smithee, left, identified the gunman as 19-year-old Santino William Legan. (Mario Tama/Getty Images)

"Ayyy garlic festival time," he wrote in the caption to the picture of people walking through the festival grounds. "Come get wasted on overpriced sh-t."

Another photograph posted on Sunday showed a sign warning of a high danger of forest fires. Its caption urged people to read "Might is Right," a racist and sexist treatise written by the pseudonymous author Ragnar Redbeard in the late 19th century.

Other witnesses described the chaos that ensued during the shooting.

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

Van Breen said he heard someone shout: "Why are you doing this?" and the reply: "Because I'm really angry."

"What's going on?" a woman can be heard asking in one video. "Who'd shoot up a garlic festival?"

Watch as people disperse from the festival as shots ring out:

Witnesses reported confusion and panic as shots rang out at the Gilroy Garlic Festival in Northern California. Three people were killed and at least 15 others injured. 0:28

'Throwing tables' to get out

Evenny Reyes, 13, told the San Jose Mercury News that at first she thought the gunfire was fireworks but then saw someone with a wounded leg.

"We were just leaving and we saw a guy with a bandana wrapped around his leg because he got shot," Reyes told the newspaper. "There was a little kid hurt on the ground. People were throwing tables and cutting fences to get out."

Founded in 1979, the Gilroy Garlic Festival is an annual event run by volunteers and held outdoors at Christmas Hill Park.

Weapons of any kind are prohibited, according to the event's website, which also said anyone wearing clothing or paraphernalia indicating membership in a gang, including a motorcycle club, would be refused entry.

"I want to express my extreme shock and sadness about what's happened today," said Gilroy Mayor Roland Velasco at a Sunday night news conference.

"I would ask for the thoughts and prayers of the community as our Gilroy police officers continue to investigate this tragic and senseless crime."