As thousands of students walked out of their schools on Wednesday to pressure Congress to approve gun control legislation, three other students were healing from wounds inflicted when a teacher’s firearm accidentally discharged in a California classroom.

The teacher, Dennis Alexander, who is also a city councilman in Seaside, Calif., was showing the students a gun on Tuesday during his advanced public safety class at Seaside High School when the gun accidentally went off, Marci McFadden, a spokeswoman for the Monterey Peninsula Unified School District, said in a phone interview on Wednesday.

Mr. Alexander was pointing his gun at the ceiling when it fired, she said, causing pieces of the ceiling to fall to the floor. Ms. McFadden said that California law and district policy prohibit teachers from bringing guns on campus.

Cmdr. Nick Borges of the Seaside Police Department said in an email on Wednesday that nobody suffered serious injuries, however, a piece of bullet shrapnel ricocheted and hit one 17-year-old on the neck, and two other students were also hit by debris.