The 15-year-old Turkish Kurd was arrested soon after attacking the teacher, who was injured in the outdoor attack in central Marseille, according to prosecutor Brice Robin.
The teen invoked allah and IS after he was detained, saying “the Muslims of France dishonour Islam and the French army protects Jews”.
He attacked the teacher from behind, slashing him in the shoulder, and then as the man tried to run away, Mr Robin said.
The knife attack comes days after a man with a butcher knife was shot dead after authorities said he went after police in central Paris.
That man’s identity has not yet been confirmed but German authorities say he had lived at a shelter for asylum-seekers in the western city of Recklinghausen.
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 on Friday at Perpignan’s main mosque.