I need to rephrase your sentence, but you could say something like this:
He was the Pied Piper of their misbehaviour.
This is a reference to the Pied Piper of Hamelin. From Wikipedia:
The Pied Piper of Hamelin (German: Rattenfänger von Hameln, also known as the Pan Piper or the Rat-Catcher of Hamelin) is the titular character of a legend from the town of Hamelin (Hameln), Lower Saxony, Germany. The legend dates back to the Middle Ages, the earliest references describing a piper, dressed in multicolored ("pied") clothing, who was a rat-catcher hired by the town to lure rats away with his magic pipe. When the citizens refuse to pay for this service, he retaliates by using his instrument's magical power on their children, leading them away as he had the rats.
In the schoolteacher example, the teacher is, metaphorically, doing something bad and is inducing the students to listen to his tune and follow his lead.
Although not an idiom per se, Pied Piper has become idiomatic as a noun to describe someone, or some behaviour, that involves entrancing a group into certain behaviour.