In a forceful judgment, Sheriff Charles Palmer told Francis Wilson, aged 50, from Prestwick: "You will be given an absolute discharge with no stain on your character."
When he was told that Dr Wilson's 21-year career had probably been ruined by an isolated incident, the sheriff commented: "I don't see why. I hope the education authority take on board what I am going to do about it."
Sheriff Palmer said the teacher had "cracked in circumstances in which I would have thought many people would have cracked" and added: "The young lad seems to have been causing a lot of trouble and to have been the architect of his own misfortune."
Perthshire and Kinross Council said it would consider the matter in line with normal procedures.