BEIJING — A former Chinese elementary school teacher has been executed for molesting or raping 26 students, some as young as 4, in a case underscoring the vulnerability of rural children left behind by parents seeking jobs in cities.

The intermediate People’s Court in the impoverished western province of Gansu said it carried out the sentence against Li Jishun on Thursday after it was upheld by the nation’s Supreme People’s Court. Li committed his assaults in the classroom, dormitories and surrounding forest areas in 2011-2012.

In its ruling, the Supreme Court said all of Li’s victims were girls younger than 12 who attended his village boarding school and “were his responsibility to educate and protect.”

“However, he took advantage of his status as teacher to repeatedly rape and molest the young girls, concealing his crimes and making it more difficult for his victims to resist and expose him,” the ruling said.

The ruling said many of the girls had been left by parents working in cities, a group of children seen as particularly prone to physical and psychological abuse and who often grow up lonely and emotionally scarred. Such children are often left in the care of grandparents or placed in boarding schools where they are looked after by teachers.

While China’s wealthy cities produce some of the world’s highest achievers in math and science, village schools are usually badly underfunded and most students leave after the mandatory nine years of education or earlier.