Mike Barile, 51, was found guilty last year at Dundee Sheriff Court of assaulting two schoolboys in the classroom after they swore at him.

Although he lost his appeal, in an unusual move the appeal court criticised the procurators-fiscal in Dundee for taking the case against him in the first place.

The decision concludes that it is “difficult to understand why it was thought to be in the public interest” to pursue the case against the maths teacher.

Earlier this year 200 people joined a demonstration in defence of Barile, who they said was subjected to a “disgraceful” hate campaign after being convicted. They waved placards that read “What about teachers’ rights?” and “Neducation no more”.

Barile’s home was subjected to a series of attacks. Eggs were thrown at the window, Superglue squirted into the lock of the front door and a tyre on his wife’s car was slashed.

Teenagers had reportedly been abusing Barile’s disabled wife Moira and the family were reported to be taking steps to sell their home.

Yesterday’s decision states: “As can be seen from the findings in fact the behaviour of the complainers was accurately described by the procurator-fiscal depute as disgraceful. Both complainers seemed to accept at times that their behaviour was unacceptable however in general they seemed proud of what they did in class and of how they treated the appellant.”

The Justiciary Appeal Court in Edinburgh was told this was the first time in more than 25 years that it had been asked to consider the law relating to teachers and how far they may be entitled to go in imposing discipline.

Barile was found guilty of grabbing one 15-year-old by the lapels of his school top and threatening to throw him “through a blackboard”.

He was also found guilty of placing his forearm across the chest of another 15-year-old boy and pinning him against a wall.

The two assaults took place at Lawside Academy in Dundee, now known as St Paul’s, between October 15, 2007 and May 30 last year.

His appeal was rejected but the judges questioned the validity of the case and made clear that under common law teachers, like parents, can use reasonable or moderate force to control a child.

The judgment states: “We would wish, however, to add this. The sheriff, who chose only to admonish the appellant, found that he had acted under extreme provocation in the face of behaviour by the pupils which was ‘disgraceful’. He informs us that he observed, when sentencing the appellant, that had he not been a teacher it’s unlikely that he would have been prosecuted.

“Not only do we entirely agree with these observations, but we have to say that, even allowing for the fact that the appellant was a teacher, given the extreme provocation he faced in the form of the complainers’ disgraceful behaviour and given the relatively insignificant nature of his physical response, it is difficult to understand why it was thought to be in the public interest … to bring criminal proceedings at all.”

A Crown Office spokesperson said: “The procurator-fiscal in Dundee received a report concerning alleged assaults committed by Michael Barile at Lawside Academy, Dundee. After full and careful consideration of the facts and circumstances, it was decided that there was sufficient evidence to proceed and that a prosecution was in the public interest.

“The trial resulted in a conviction on two charges of assault, a decision which was upheld at today’s appeal hearings. We note the Appeal Court’s comments, which were based on its consideration of the case after trial.”

An EIS spokesman said: “While the EIS will not comment on any individual legal case, there is very great public concern over the types of behaviour that many teachers have to face in the course of their working lives.”