San Diego Police Chief Scott Wahl said local law enforcement and the FBI were investigating the attack on the largest mosque in San Diego County as a hate crime.
However, no precise motive or precipitating incident for the gun violence has been publicly suggested by authorities.
All of the children attending a day school at the mosque complex were accounted for and safe after the shooting, which erupted about 11.40am on Monday, officials said.
The mother of one of the two suspects had called police about two hours before the shooting to report that her son, whom she described as suicidal, had run away from home taking three guns she owned and her vehicle.
She said her son was with a companion and the two were dressed in camouflage. Police initiated efforts to track down the youths and were dispatching patrols to a nearby shopping mall and the son's high school as a precaution when calls came in reporting the mosque shooting.
The chief declined to disclose the contents of a note he said was found by the runaway's mother.
Prior to the shooting police were not made aware of any specific threat to the mosque or any religious centre, school, shopping area, or any other place, Wahl said.
The attack came the week before the major Muslim holiday of Eid al-Adha or Feast of the Sacrifice and the annual Hajj pilgrimage of Islamic faithful to the holy site of Mecca in Saudi Arabia.
"We have never experienced a tragedy like this before," Taha Hassane, the imam and director of the Islamic Center, told reporters.
"It is extremely outrageous to target a place of worship."
Scores of law enforcement officers called to the scene encountered the bodies of the three men affiliated with the mosque shot dead. Officials credited the slain security guard as likely having helped prevent further bloodshed.
A short time later, police discovered the bodies of two teenage males, aged 17 and 18, in a vehicle in the middle of a street, dead from apparently self-inflicted gunshot wounds. Police originally put the age of the older youth at 19.
Wahl said 50 to 100 police officers from across the San Diego area immediately responded to the first "active shooter" call and within four minutes had converged on the mosque, located in the residential-commercial Clairemont district of California's second-most populous city.
Footage from local television stations showed dozens of patrol cars on a highway bridge, police in tactical gear armed with rifles perched on the roof of the mosque near its dome, and armed officers on the ground making their way through the complex.
Wahl said no shots were fired by law enforcement during the episode.
Five hours after the shooting, the police chief said investigators were still piecing together details of what may have ignited the violence and how it transpired.
The Islamic Center is the largest mosque in San Diego County and houses the Bright Horizon Academy, a school providing Islamic education.
Although random gun violence has become a common occurrence in public places across the United States, Muslim and Jewish communities have grown particularly apprehensive since US and Israeli forces launched airstrikes on Iran on February 28, and Iran responded with its own air attacks on Israel and several Gulf states, sparking an intensifying war across the region.
with Reuters