A semi-automatic handgun went off accidentally inside the backpack of a 12-year-old girl in a Los Angeles middle school classroom, sending a single bullet tearing through the wrist of another girl before hitting a boy in the head, police said Friday.

Los Angeles police spokesman Josh Rubenstein said detectives are trying to figure out where the girl got the gun, which was unregistered, and why she brought it to school. It wasn't clear what made it fire.

The girl, who was taken into custody minutes after the shooting, has retained an attorney and isn't answering questions, Rubenstein said. She is expected to be arraigned Monday on two felony charges, including being a minor in possession of a firearm and having a weapon on school grounds, prosecutors said.

Jordan Valenzuela, a 12-year-old classmate of the girl's, told The Associated Press that he was in the room next door when the gun went off and talked to her minutes later.

"She was crying," Jordan said. "She was like, 'I didn't mean to. I had the gun in my backpack and I didn't know it was loaded and my backpack fell and the gun went off.'"

Jordan said he saw a hole in the backpack, which the girl was holding, when she asked him to hide the gun for her.

"I said 'No,'" he said. "Then I moved away from her because I was a little bit scared."

The shooting sent children screaming and crying from the classroom as blood poured from the two students who were hit. Police descended on the school, which was put on lockdown, and the girl was arrested without incident.

Terrified parents rushed to the campus and waited for hours to be reunited with their children. Once they did, many children and parents sobbed as they hugged, walking from the school as they held each other.

The 15-year-old boy who was hit in the head with a bullet initially was in critical condition.

A spokesman at Los Angeles County-USC Medical Center where the children were being treated didn't respond to messages about his condition Friday, though a doctor treating the boy said he expected him to make a full recovery.

The wrist wound to the 15-year-old girl was considered minor. Three others had superficial face or head injuries, some from broken glass.

A review of shootings nationwide by The Associated Press and USA TODAY Network found that at least 141 deaths of minors were attributed to unintentional or accidental shootings in 2015.

Most accidental shootings involve someone actually handling firearms, as opposed to guns getting dropped, said Pete Gagliardi, a former longtime agent with the U.S. Bureau of Alcohol, Tobacco and Firearms.

"It's pretty rare to hear about an incident like this," Gagliardi said of Thursday's shooting.

He said the gun wouldn't necessarily had to have been cocked to go off in the girl's backpack, but mostly likely would have had to have become entangled with something inside the bag for the trigger to have been pressed.

A strikingly similar shooting to Thursday's happened just south of Los Angeles in Gardena on Jan. 18, 2011, when a gun went off inside a 17-year-old boy's backpack after he set it on a desk, wounding two students with one bullet, including a girl who was shot in the head.

The teen was convicted of possessing and discharging a firearm in a school zone. He was sentenced to nine months in juvenile camp and put on probation until he turned 21.

The Los Angeles Unified School District has a policy requiring every middle and high school campus to conduct daily random searches by metal-detector wands at different hours of the school day for students in the sixth grade and up.

This story has been updated.