A 15-year-old girl was in critical condition with a head wound and a 15-year-old boy suffered a neck wound, said Deputy Chief Patrick Gannon. Both were hit with the same bullet.
The student who brought the gun apologized before running to a classroom, Gannon said.
"He said, 'I'm sorry,' when the gun went off. It made it appear to the teacher that it was an accident," Gannon said.
The shooting occurred in a classroom at Gardena High School, Officer Gus Villanueva said. Principal Rudy Mendoza said students were on a break at the time.
Officers took the youth into custody and transported him to a police station while the school 15 miles south of downtown remained locked down.
Nelda Robledo, one of the worried parents who gathered near the school, said her 16-year-old daughter texted her that after the shooting students were ordered to get down on the ground or hide in a corner.
Police initially reported that three people were shot and the shooter was at large.
Numerous law enforcement agencies responded to the 2,400-student campus located in the city of Los Angeles adjacent to the city of Gardena.
Gardena police Lt. Steve Prendergast said a teacher called 911 at 10:41 a.m. and Gardena officers initially responded. The investigation was turned over to Los Angeles city and Los Angeles Unified School District police.
As at many district schools, Gardena High School checks incoming students with security wands at the entrance. It's unclear how the student got in with the gun in his backpack, said district spokeswoman Gayle Pollard-Terry.
"We're trying to find out if the wanding is random or if every student is wanded," she said.
Pollard-Terry said each school decides whether it needs to check students with a wand. No district school is equipped with walkthrough metal detectors, she said.
Several parents interviewed at the scene said their children described a lot of racial tension at the school.
"There's usually fights everyday, you're going to see blacks against whites and whites against blacks every single day," said Christy Westbrooks, whose 16-year-old daughter attends the school. "Spanish, whites, Samoans - they don't care what race. Every day there's a fight."
Discipline has long been a problem at Gardena, which ranks one of the district's lowest-performing high schools. Roughly 35 percent of students drop out.
Five years ago, more than 2,000 suspensions were given out, and 15 students expelled. Those figures remained high until last year when the number of suspensions dropped to 300 and expulsions to two.
Forming a discipline committee was one of the principal's goals for this year, according to the school's website.
Frantic parents rushed to the school after hearing about the shooting on the news. They paced nervously as they waited behind police tapes for word from their children.
"I've never heard of anything like this before," said Thomas Hill, whose 16-year-old and 18-year-old children attend the school. "You're going to have confrontations between kids but never this."
A mother who was waiting to hear from her 14-year-old son, Michael, said the school has a reputation for gang violence. Lupe Contreras said she has been trying to get her son out of the school.
Cynthia Cano, 15, said she was in a Mexican-American social studies class when an announcement was made that the school was in lockdown.
"We heard someone got shot. Everyone was freaking out a little," she said in a telephone interview from inside the campus.
Associated Press writer Christina Hoag, Greg Risling, Daisy Nguyen and Sue Manning contributed to this report.