The 15-year-old Turkish Kurd was arrested soon after wordlessly attacking the teacher, who was injured in the outdoor attack in central Marseille, said Brice Robin, the Marseille prosecutor.
The teen invoked Allah and the extremist group only after he was detained.
He attacked the teacher first from behind, slashing him in the shoulder, and then went after the man again as he tried to run away, Robin said.
Both incidents coincide with high tension in France, which last week marked a year since the January attacks against the Charlie Hebdo newspaper and a kosher supermarket that left 17 people dead.
Over the weekend, two churches were burned and a boar's head and racist inscriptions were found Friday at Perpignan's main mosque.
