The gunman was shot dead by police shortly after he began firing, although police are investigating reports that a second suspect may still be at large.
The gunman used a rifle and gained entry to the Gilroy garlic festival by cutting through a fence to avoid tight security, including metal detectors, police said.
Michael Paz, 72, a hat vendor at the festival, told the San Francisco Chronicle that he saw a gunman armed with a rapid-fire assault rifle.
"He came ready to shoot because he was wearing a protective vest," Paz said. "He was shooting left; he was shooting right without any particular aim."
As police swooped on the gunman and shots were fired, festival attendees dropped to the ground, Mr Paz said.
The festival revolves around the celebrated crop of the region, featuring garlic-inspired foods, drink, live entertainment and cooking competitions. It is hosted by volunteers and describes itself as the world’s greatest summer food festival.