One person was shot in the arm, and a teen boy was detained.
Law enforcement says a 15-year-old was shot in the arm.
Authorities apprehended the suspect at a Vons grocery store, about a mile from the school.
The rifle apparently used in the attack was recovered in an open field west of the school, McDonnell said.
"Unfortunately, that may be a result of why we were able to to put an end to this so quickly was this rapid deployment and rapid response", said Capt. Darren Harris of the Los Angeles County Sheriff's Department.
"That student is going to be OK", he said.
Authorities said the shooting appeared to be random but have not revealed the motive. "A bunch of kids started running out to me, towards me, with very panicked looks on their faces", Alexander said.
Harris says the school is safe but remains on lockdown as officials worked to reunite students with their parents. He said he heard one shot and turned.
Los Angeles County Sheriff's homicide detectives are investigating Saturday morning the shooting death of a man in Palmdale.
About a half-hour after the initial call, reports were received of shots being heard near the campus of Manzanita Elementary School on the 38600 block of 33rd Street East. Deputies searched the elementary school but found nothing.
At least three nearby schools - David G. Millen Intermediate, Cottonwood Elementary and Ocotillo Elementary - were on lockdown, employees there said.
Palmdale is north of Los Angeles in the high desert Antelope Valley.
McDonnell said the boy's mother had called the officer earlier in the morning to tell him she and her husband were having trouble with him and that the teen had run away. "Alexander, turn around, turn around, there's an active shooter.' And I didn't really have time to react to that because nearly immediately after that I heard one single gunshot very loud and very close by". Students on the campus remained calm and texted their classmates, telling them to stay away from the area, and faculty members directed deputies throughout the campus, allowing them to clear the building faster, McDonnell said.