Music teacher Marston Riley, 64, is seen in video footage confronting a 14-year-old student for not wearing the proper uniform.

Los Angeles: A California high school teacher is facing charges for punching a pupil who had hurled racial slurs at him, in an incident that many students and staff say was justified.

Music teacher Marston Riley, 64, is seen in video footage confronting a 14-year-old student for not wearing the proper uniform.

Students told the local KTLA news station that the teen refused to leave the classroom as instructed and began shouting profanity and the N-word at Riley, who is black. The boy also threw a basketball at Riley, the students said.

Footage of the incident -- which took place last Friday at Maywood Academy High School, in southeast Los Angeles -- shows Riley repeatedly punching the student, who appears to hit back once.

The brawl ended after a school security officer and students intervened to separate the pair.

The student, who was not identified, was transported to a hospital with moderate injuries and later released, the Los Angeles County Sheriff's Department said in a statement.

It added that Riley was arrested on suspicion of child abuse and was released on Saturday after posting bail. He is scheduled to appear in court on November 30.

Many students, staff and parents have come to the defense of Riley, saying the student had pushed him to the limit. But some parents expressed outrage, insisting that nothing could justify a teacher beating a student.

"I had this teacher before and I had no problem with him," one student told KTLA. "He was a really nice teacher, I always respected him. He always had a really good relationship with every student."

Scores of people also defended Riley on social media, saying the boy was out of line and got what he deserved.

Cecilia Diaz Jimenez, a former teacher at the school who set up a GoFundMe page for Riley, said he was a "great person and a great teacher."

As of mid-morning on Monday, the page had raised nearly $38,400 of its $50,000 goal.

"We all may have mixed feelings about what happened," Jimenez said. "But please do know that this is not the first time that Mr Riley is attacked, physically or verbally."

In a statement, officials with the Los Angeles Unified School District, said they were "extremely disturbed" by the incident and were cooperating with the police probe into the fight.

"We take this matter very seriously and do not condone violence or intolerance of any kind," the statement says.