DETECTIVES in California are investigating what prompted a man to go on a shooting spree in the beachfront city of Santa Monica, killing four people before he was shot dead by armed police.

The man, said to be in his late twenties, shot two people dead in a house before opening fire on a bus, surrounding streets and a community college. Unconfirmed reports said the first two victims were his father and brother.

Witnesses said the man was dressed in black and carrying an assault-style rifle. Five other people were wounded during the spree, which ended on a college campus where police say they shot the gunman in the library.

President Barack Obama was attending a political fundraiser about three miles from where the carnage unfolded, just before noon on Friday. Police say it began at a house east of the college, where the gunman shot two people before apparently setting fire to the home.

The man then fled and carjacked a woman, spraying bullets at bystanders and pedestrians as he went along. Eyewitnesses said at least several rounds were fired at a city bus before he arrived at Santa Monica College.

A driver leaving a car park at the campus was killed and two passengers wounded as the car crashed through a wall.

From there, the gunman entered the campus, fatally wounding a woman as he made his way towards the college's library, where students were studying for final exams.

The gunman continued to shoot at people in the library, but did not hit anybody there as dozens fled for their lives.

Police eventually shot him in the library, which is about a mile from the city's famous Santa Monica Pier and sandy beaches.

Students described a scene of pandemonium as the sounds of gunfire rang out, sending people scurrying for cover.

One said: "I heard a girl screaming. She said 'no, no, please no'."

Student Isamar Ortiz said: "We didn't know what it was until somebody started screaming and saying that there was shooting and when we heard that there was shooting we just immediately got up and got out of the building.

"Everyone just rushed outside and we didn't know what was going on until they told us there was a shooting in the front of the library."

After the gunman was killed, police wearing helmets and armed with shotguns and rifles searched the campus for a possible second shooter.

A man dressed entirely in black, with the words Life is a Gamble on the back of his sweatshirt, was seen being led away in handcuffs. A police spokesman said he was questioned and released and was not a suspect.

Santa Monica Police Sergeant Richard Lewis said investigators had yet to uncover a motive for the rampage, adding: "It's a horrific event that everybody wishes had never happened."

The bloodshed did not appear to be related to Obama's visit to Santa Monica and the Secret Service called it a "local police matter".

Three of the gunman's victims died immediately. Another woman died at Ronald Reagan UCLA Medical Centre, where she had been admitted in a critical condition.

Two other women were also admitted to the hospital and one was in a critical condition after undergoing surgery. The other arrived in a serious condition and is now said to be stable.

Three other women went to UCLA Medical Centre Santa Monica with relatively minor injuries.

Jerry Cunningham Rathner, who lives near the house that was set on fire, said she heard gunshots and came out on to her porch to see a man shooting at the residence.

She said the building erupted in flames and was billowing smoke.

The gunman, who was wearing an ammunition belt, is said to have pointed a rifle at a woman in a car and told her to pull over.

He then signalled to a second car, also driven by a woman, to slow down and began firing into the vehicle. She said: "He fired three to four shots into the car – boom, boom, boom, right at her." She went to the woman's aid and saw she was wounded in the shoulder. The gunman then abducted the woman in the first car and drove away.

The chaos then shifted to Santa Monica College, which has about 34,000 students.

The killing spree marks the latest in a string of mass shootings over the past year, including a December attack in Connecticut that killed 20 children and six adults at a school, and a shooting last July at a Denver cinema that killed 12 people.

The attacks have reignited a national debate over gun violence in America that spurred Obama and many of his fellow Democrats to push for expanded background checks for gun buyers – an initiative defeated in the US Senate.

In a separate incident on Friday, a four-year-old boy accidentally shot and killed his father at a friend's home in Prescott Valley in northern Arizona.

Police said the boy somehow found a gun in the home's living room and accidentally fired it and a bullet hit his 35-year-old father, who was rushed to a hospital where he died.

Police identified the man as Justin Stanfield Thomas.