The gunman, named as 53-year-old Cedric Anderson, shot dead his estranged wife, a teacher, and wounded two children who were behind her, one of whom died of his wounds.
He then turned the gun on himself, police said.
Police chief Jarrod Burguan described the incident as a suspected “murder-suicide” attempt.
The shooting happened at 10:30 local time at North Park Elementary School in San Bernardino county, 60 miles east of Los Angeles.
The gunman had gained entry to the school as a visitor and kept his weapon concealed until he opened fire in the classroom where 15 children with special needs were being taught, authorities said.
Cedric Anderson killed his wife Karen Elaine Smith and fatally wounded 8-year-old Jonathan Martinez, who was airlifted to hospital but later died.
A 9-year-old pupil remains in hospital in a stable condition, the Los Angeles Times reported.
Jarrod Burguan tweeted shortly after the incident that the suspect was “down” and there was “no further threat”. The school was immediately evacuated.
Up to 600 students were transferred by bus to nearby Cajon High School, where they were later met by their parents.
“Police operations are continuing to secure the area,” Jarrod Burguan said earlier on Twitter.
He added: “However, we do believe the threat is down.”
In December 2015, 14 people were killed and 21 others wounded when a couple entered a disabled service centre in San Bernardino and began firing at a group of county health workers.
Image source: Wikimedia Commons President-elect Donald Trump celebrated his election victory at the Ultimate Fighting…
Millions of voters across the US chose to return Donald Trump to the White House…
Donald Trump declares victory in the US election as he addresses jubilant supporters in Florida.…
Stocks around the world are rising as Donald Trump appears to be on the cusp…
Donald Trump has won Pennsylvania, North Carolina and Georgia and taken a lead over Kamala…
Quincy Jones, the celebrated musician and producer who worked with Michael Jackson, Frank Sinatra, Ray…