Authorities were investigating a possible link between the shooting on Friday night in the town of Isla Vista near the campus of the University of California at Santa Barbara and a threatening video posted online.
In the YouTube video, a young man bitterly complained of loneliness and rejection by women and said he planned to kill people. The video appears to have been made by the suspect, Santa Barbara Sheriff Bill Brown told reporters.
Witnesses reported seeing someone driving a black BMW through the streets and shooting at people in Isla Vista, a beachside community where many college students live.
"It's obviously the work of a madman," Brown said at a news conference. "There's going to be a lot more information that will come out that will give a clearer picture of just how disturbed this individual was."
Seven people died in the rampage, including the suspect, Brown said.
He did not identify the suspect but a lawyer for the suspected gunman's family tentatively identified him as Elliot Rodger, son of a Hollywood director.
"I cannot confirm that but we believe it," the attorney, Alan Shifman, told reporters outside the family home in the Woodland Hills neighborhood of Los Angeles. "But the police would not give us 100 percent (certainty)."
"We offer our deepest, compassionate sympathy to the families involved in this terrible tragedy," Shifman told reporters, reading from a prepared statement on behalf of the family. "We are experiencing the most inconceivable pain and our hearts go out to everyone involved."
The suspected gunman's father was Peter Rodger, an assistant director on 2012 film "The Hunger Games."
Brown said deputies twice exchanged fire with the suspected gunman before his vehicle crashed. He said the man died of a gunshot wound to the head but could not immediately say if he was killed by deputies or a self-inflicted wound. It also was not known whether he was a UCSB student.
A semi-automatic handgun was recovered from the scene, Brown said.
The YouTube video police were studying showed a young man who identified himself as Elliot Rodger pouring out his hatred of women who have rejected him and "popular kids." He said he was about to kill people out of loneliness and sexual frustration.
The video appeared to have been uploaded to YouTube on Friday night, shortly before the shooting. "It would appear that is connected," Brown said.
YouTube has since removed the video, posting in its place a notice saying it violated its terms of service. A spokeswoman for Google, which owns YouTube, was not available for comment.
The identities of the dead were withheld pending notification of their families, Brown said. Santa Barbara Cottage Hospital was not releasing details about the conditions of the wounded in Friday's shooting.
Robert Johnson, a 21-year-old UCSB student, said he first noticed trouble after a car drove past him at a busy Isla Vista intersection and he then heard "popping noises" that he originally mistook for firecrackers or the car backfiring.
"Then the sound came again, and by that point it had pulled up in front of a convenience store deli, and someone in the car was firing into a crowd of about eight, 10 people that were gathered in front of the store," he said.
"Everyone that was being fired upon, they all jumped and scrambled to run inside the store," he said.
The car had darkly tinted windows and the occupant was not visible, Johnson said.
College student Brad Martin told a UCSB student newspaper that his girlfriend was "absolutely hysterical" after being approached by the gunman with a weapon she initially was not sure was real.
"She said the next second he raised it up to her face ... and she turned around and started running," Martin told the Daily Nexus. "That's when she heard 'bang, bang, bang' right behind her as she was running."
UCSB President Janet Napolitano said she was "shocked and deeply saddened" by the shooting near the campus.
"Our thoughts and prayers go out to the victims of this tragedy, their families and the entire Santa Barbara community," she said in a statement.
Napolitano, formerly U.S. secretary of Homeland Security, said victims' families still were being notified.
The university was offering services to family members, faculty and students, including counseling, she said.
The incident was the latest mass shooting in the United States, where schools, shopping malls and military bases have been scenes of such crimes.
Last month, a gunman killed three people and himself at the Fort Hood U.S. Army base in Texas, where another gunman killed 13 people in 2009.
In December 2012, 20 children and six adults were killed in a mass shooting at an elementary school in Newtown, Connecticut. Six months before that, a gunman killed 14 people in a Denver-area movie theater.
The deadliest U.S. mass shooting in modern times was in 2007, when a student at Virginia Tech killed 32 people in a shooting spree.
Some 23,000 people live in Isla Vista. Many are students at UCSB, which has an enrollment of about 22,000, or at Santa Barbara City College.