The 19-year-old California gunman who killed three people and wounded around a dozen others when he opened fire at the Gilroy Garlic Festival had mocked the food event on social media, police said.

Santino William Legan cut through a fence at the festival on Sunday evening and seemingly shot people at random with an “AK-47-style” assault rifle, according to Gilroy police chief Scot Smithee.

Legan, fatally shot by police within a minute of the attack, appeared to post a photograph from the festival on his Instagram account shortly beforehand, with captions expressing his disdain.

“Ayyy garlic festival time,” he wrote beneath a picture of people walking through the festival grounds. “Come get wasted on overpriced s***.”

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 in the 19th century.

Mass shootings in America Show all 8 1 /8 Mass shootings in America Mass shootings in America Camden shootings – 1949 Howard Unruh killed 13 people, including three children, during a 12-minute walk through his neighborhood on September 6, 1949, in Camden, New Jersey, when he was 28 years old. The incident became known as the "Walk of Death". Unruh was found to be criminally insane and died in 2009 after a lengthy illness at the age of 88, following 60 years of confinement. Alamy Mass shootings in America University of Texas tower shooting – 1966 Charles Whitman killed 17 people and injured 31 others in Austin, Texas. After stabbing his mother and wife the night before, he headed to the University of Texas, where he opened fire on people in the campus and streets from the observation desk. He was shot dead after a policeman and civilian reached the scene. Austin History Center, Austin Public Library Mass shootings in America Easter Sunday Massacre – 1975 James Ruppert killd 11 family members in his mother's house, which included his mother, brother and his wife, as well as their eight children. He used a magnum, two handguns and a rifle. Mass shootings in America Wilkes-Barre shootings – 1982 Former prison guard, George Banks, shot dead 13 people in Pennsylvania, including five of his own children. AP Photo/Times Leader Mass shootings in America Wah Mee massacre – 1983 Three men, Kwan Fai Mak, Wai-Chiu Ng, and Benjamin Ng, killed 13 people who were in Seattle's Wah Mee gambling club. YouTube/KIRO 7 News Mass shootings in America San Ysidro McDonald's massacre – 1984 James Huberty killed 21 people and injured 19 others after he walked in a McDonald's in San Diego. He was shot dead by a sniper after 78 minutes of him entering the restaurant. Alamy Mass shootings in America Palm Sunday massacre – 1984 Ten people were shot dead from handguns at close range in a New York home. A baby girl was the only survivor after convicted dealer, Christopher Thomas, shot three women, one teenage girl and six children in their Brooklyn home. Thomas was convicted of manslaughter and cleared of murder. He was released from prison after 32 years. Mass shootings in America Edmond post office shooting – 1986 Patrick Sherrill, a postal worker at the Edmond post office in Oklahoma, killed 14 co-workers and injured 6 others, before he shot himself. Oklahoma Highway Patrol Collection

“Why overcrowd towns and pave more open space to make room for hordes of mestizos and Silicon Valley white tw**s?” the caption said. The term “mestizo” refers to people of mixed race. The account was only a few days old, and was deactivated on Monday.

Donald Trump described the gunman as a “wicked murderer” following the mass shooting.

Police and FBI agents are still trying to determine a motive for the shooting and investigating unconfirmed reports by witnesses that Legan may have had an accomplice.

“It could have gone so much worse so fast,” Mr Smithee said, noting that the festival, which takes place about 30 miles southeast of Silicon Valley, is attended by thousands of visitors.

Gilroy Police Department chief Scot Smithee speaks during press conference (EPA)

The police chief said that search warrants had been obtained for a home in Gilroy associated with the suspect and a car that officers believe he drove to the festival.

Investigators believe Legan – who was originally from Gilroy – purchased the rifle legally on 9 July in Nevada, where he had recently been living.

He was believed to evaded metal detectors and other security measures at the entrance by cutting through the fence, police said.

Legan killed two children and a man in his 20s, and at least 11 people were treated for wounds, according to Santa Clara Health System. Early police reports said that one person was in critical condition on Sunday.

The Santa Clara County Medical Examiner-Coroner identified the victims as Stephen Romero, six, and Keyla Salazar, 13, of San Jose, and Trevor Deon Irby, 25, of Romulus, New York.

Stephen Romero, aged 6, was killed in the Gilroy mass shooting (Kerry Romero / Universal News and Sport) (Kerry Romero/Universal News And Sport)

The six-year-old child’s grandmother, Maribel Romero, described Stephen as a loving boy who was “always kind, happy and ... playful”.

His mother and his other grandmother were also shot and were being treated in hospital, Ms Romero told media.

Founded in 1979, the Gilroy Garlic Festival is an annual event run by volunteers and held outdoors at Christmas Hill Park. The agricultural community bills itself as the “Garlic Capital of the World”.