In February, Patrice Motz, a veteran Spanish teacher at Great Valley Middle School in Malvern, Pa., was warned by another teacher that trouble was brewing.

Some eighth graders at her public school had set up fake TikTok accounts impersonating teachers. Ms. Motz, who had never used TikTok, created an account.

She found a fake profile for @patrice.motz, which had posted a real photo of her at the beach with her husband and their young children. “Do you like to touch kids?” a text in Spanish over the family vacation photo asked. “Answer: Sí.”

In the days that followed, some 20 educators — about one quarter of the school’s faculty — discovered they were victims of fake teacher accounts rife with pedophilia innuendo, racist memes, homophobia and made-up sexual hookups among teachers. Hundreds of students soon viewed, followed or commented on the fraudulent accounts.

In the aftermath, the school district briefly suspended several students, teachers said. The principal during one lunch period chastised the eighth-grade class for its behavior.

The biggest fallout has been for teachers like Ms. Motz, who said she felt “kicked in the stomach” that students would so casually savage teachers’ families. The online harassment has left some teachers worried that social media platforms are helping to stunt the growth of empathy in students. Some teachers are now hesitant to call out pupils who act up in class. Others said it had been challenging to keep teaching.