LOS ANGELES — A 14-year-old California student stood next to his high school music teacher, repeatedly used a racial epithet and threw a basketball at him.

The teacher, who is black, punched the boy in the face and kept swinging as other students recorded the incident with their cellphones.

The fight Friday in the Maywood Academy High School classroom — video of which has gone viral online — led to the arrest of teacher Marston Riley, 64, on suspicion of child abuse. Detectives with the Los Angeles County Sheriff’s Department’s Special Victims Bureau are investigating.

Students told Los Angeles TV station KTLA that the confrontation began after Riley asked the boy to leave the classroom because he wasn’t wearing a proper uniform.

Cellphone video from the classroom shows the boy standing next to his teacher, swearing at him and repeatedly using racial slurs.

“What’s up, bro?” the student says as he stands close and throws the basketball at Riley.

“Why you wisecracking, my … ?” he asks.

Riley walks away as the student continues to insult him, then walks back to the front of the classroom where the student is standing. He calmly tells the student several times to leave, then suddenly starts punching.

The two trade punches as other students scramble around them, some shrieking. Riley hits the student numerous times, and a woman in a yellow safety vest tries to intervene.

The boy was pulled from the room by campus staff.

The student was taken to a hospital where he was treated for moderate injuries and released, according to the Sheriff’s Department.

Riley was arrested and booked at the East Los Angeles sheriff’s station. He was released Saturday morning after posting $50,000 bail, according to Sheriff’s Department inmate records. He is scheduled to be arraigned Nov. 30, authorities said.

Riley could not be reached for comment.

In a statement, officials with the Los Angeles Unified School District said they were “extremely disturbed” by reports of the fight.

“We take this matter very seriously and do not condone violence or intolerance of any kind,” the statement read. “Los Angeles Unified is cooperating with law enforcement in investigating this incident.”

Crisis counselors and additional school police patrols will be at Maywood Academy High on Monday, the district said.

On social media, scores of people defended Riley, saying that he was pushed to the brink and that the student was out of line for using racial epithets. A GoFundMe page for him had raised more than $18,000 by Sunday evening.

Some students stood by their teacher. One student, who did not give his name, told KTLA that he had Riley as a teacher in the past and “had no problem with him.”

“He was a really nice teacher,” the student said. “I always respected him. He always had a really good relationship with every student.”

Several parents gathered outside the school Friday night to express their anger over the incident, NBC Los Angeles reported.

“Just the fact that he’s hitting a child — it’s not right,” one woman told the station.