The student who opened fire at his Southern California high school on his 16th birthday, killing two students and injuring three others before shooting himself in the head, died Friday, Los Angeles County Sheriff's officials said.

He "was being treated for a self-inflicted gunshot wound to the head, when he succumbed to his injuries," officials said in a statement. "His mother was present at the time of his passing."

Earlier Friday, Los Angeles County Sheriff Alex Villanueva said the Thursday morning attack appeared to have been planned, but, "it still remains a mystery why."

"We know it was a planned attack," he said. "It was deliberate."

The suspected gunman, identified by multiple law enforcement officers as Nathaniel Tennosuke Berhow, pulled a .45 caliber semi-automatic pistol from his backpack in the quad area of Saugus High School and opened fire, according to officials.

The first reports of the shooting were logged at 7:38 a.m. Thursday, they said.

The suspect had been dropped off at school by his mother, the sheriff said. He was standing by himself, walked to the quad area, dropped his backpack and started firing, striking random targets, Villanueva said.

He cleared a malfunction with the weapon and was able to squeeze off several shots, all within 16 seconds, the sheriff said. He "seemed very familiar with firing the weapon," he said.

Villanueva said students recently underwent active shooter training and when violence erupted Thursday, "did exactly as they were trained" by running and hiding.

School resource Deputy James Callahan told reporters he was on-scene within minutes and administered CPR to victims. "I immediately entered the school ... and saw three gunshot victims on the ground," he said.

The Los Angeles County Medical Examiner identified the deceased as Gracie Muehlberger, 16, and Dominic Blackwell, 14.

One wounded victim was released from the hospital Thursday night, while a 14-year-old girl and 15-year-old girl who were shot remained hospitalized Friday but were expected to be released in coming days.

Families in our community have suffered unimaginable loss and pain this morning. Our hearts and minds are with the victims, students, staff and families of Saugus High, as well as all those affected by this senseless tragedy. #SaugusStrong — Santa Clarita City (@santaclarita) November 14, 2019

The shooter and all of the victims were Saugus students, but Los Angeles County Sheriff's Department homicide Capt. Kent Wegener said the gunman had no known connection to the teens he shot and appears to have fired at random.

About 40 witnesses have been interviewed, authorities said.

Law enforcement sources familiar with the investigation told NBC News they are looking into the possibility the weapon used in the attack was a "ghost gun" made from untraceable parts that can be found online or even produced with at home a 3-D printer.

Detectives searched the suspect's residence in Santa Clarita, about 35 miles outside of Los Angeles, and interviewed his mother and girlfriend.

Law enforcement sources said at least six firearms found at the home belonged to the suspect's deceased father.

Wegener subsequently told reporters the weapons were being analyzed by authorities from the sheriff's department and the federal Bureau of Alcohol, Tobacco, Firearms and Explosives.

"We did not find any manifesto which would clearly identify his motive behind this assault," the captain told reporters Friday.

Berhow's father, Mark Berhow, and mother, Mami Matsuura, were in the midst of a custody battle in 2016, according to a court filing in Los Angeles county. Prior to that, Mark Berhow had been arrested during a domestic dispute with Matsuura, The Associated Press reported.

Law enforcement sources told NBC Los Angeles that Mark Berhow was detained for a mental health evaluation at the time of the custody hearings, and following the evaluation, deputies seized firearms from the home.

The following year, Mark Berhow died of a heart attack, according to an online obituary that said he was survived by his wife, his son, Nathaniel, and a daughter.

The church where Mark Berhow's funeral was held hosted a service Thursday night for the victims of the shooting, according to a Facebook post.

"His father died very recently. So apparently he had a lot of stress from that," neighbor Tom Morreale told NBC Los Angeles.

But fellow students said Berhow was a Boy Scout, who was smart and quiet, had not been bullied and showed no signs that he would become violent.

"He always had a smile on his face," another neighbor, Jacob Labrie, said.

Wegener said Thursday that the sheriff's department had not received any recent calls to the boy's house "that would indicate that there was turmoil" there.

All of the schools in Saugus' William S. Hart Union High School District were closed Friday, but counselors would be available for students and staff at a nearby church, according to a statement from deputy superintendent Mike Kuhlman.

"I know our entire school community shares my profound sadness and disbelief," Kuhlman said in the statement. "Hold your children tight. Love them. Praise them for being responsible in the face of fear."