Two teenage gunmen opened fire at the Islamic Center of San Diego, killing three men outside the mosque, one of them a security guard, before the two suspects were found dead in a vehicle nearby, police said.
All of the children who were attending a day school that is part of the mosque complex - the largest in San Diego county - were accounted for and safe after the shooting, which erupted shortly before 12pm local time (8pm Irish time), according to San Diego Police Chief Scott Wahl.
San Diego police said in a post on X that "the threat at the Islamic center has been neutralised". TV footage from a helicopter showed armed response teams gathered outside a building.
Mr Wahl said the FBI was called in to assist in the investigation of the incident, which the police chief said authorities were treating as a hate crime.
Scores of law enforcement officers encountered the bodies of three men shot dead outside the building, including a security guard who Mr Wahl credited with likely having helped prevent further bloodshed.
A short time later, police discovered the bodies of two teenage males, aged 17 and 19, in a vehicle in the middle of a street, dead from what appeared to be self-inflicted gunshot wounds, the chief said at a news conference.
Mr Wahl said investigators were still piecing together details of what precipitated the shooting and how the violence transpired.
An imam at the mosque, Taha Hassane, said that all the staff, teachers and children at the mosque were safe.
"We have never experienced tragedy like this before. And at this moment all that I can say is, sending our prayers and standing in solidarity with all the families in our community here," he said.
"It is extremely outrageous to target a place of worship," the imam added.
US President Donald Trump said the shooting at the mosque complex "terrible situation".
"At the mosque, they're giving a briefing. It's a terrible situation. I've been given some early updates but we're going to be going back and looking at it very strongly," Mr Trump told reporters.
State Governor Gavin Newsom was briefed on the apparent attack, his press office said.
"We are grateful to the first responders on the scene working to protect the community and urge everyone to follow guidance from local authorities," it said in a post on X.
Shots were also fired at a landscaper a couple of blocks away in what apparently was a separate shooting incident, though police did not say whether a connection had been ruled out. The landscaper was not injured, Mr Wahl said.