A pupil claims he was thrown out of class after a teacher reprimanded him for claiming there were only 'two genders'.

The 17-year-old secretly filmed his teacher on a smartphone telling him off and then posted the clip online.

It was shared internationally, sparking a debate about free speech and transgender rights – with one YouTube video shared more than 9,000 times.

A leading teaching union defended the 56-year-old teacher and suggested the child had been 'looking for trouble'.

Last night Aberdeenshire Council said the video did not show the full context of the incident, and insisted the school's aim was to 'support a fairer, inclusive environment for all'.

The three-minute video shows the teacher explaining to the child why he was asked to leave the class at an Aberdeen-shire secondary school, after the teenager had claimed there were only two genders.

The teacher tells the pupil: 'You're entitled to your opinion', to which the teenager responds: 'If I am, then why did you kick me out of class? It's not very inclusive.'

Then the teacher replies: 'No, I'm sorry, what you were saying is not very inclusive. This is an inclusive school.'

This teacher allegedly kicked a pupil out of class for saying that there are only two genders at a school in Aberdeenshire

The teacher then says there is more than one gender 'by law', and that by claiming there are only two genders, the pupil had not been 'inclusive'.

The member of staff continues: 'You were clearly given an opportunity not to pursue it. You chose to do so.'

At this point, the pupil tells him: 'I think it's silly to have anything other than two genders, sir.'

The teacher then urges him: 'Could you please keep that opinion to your own house? Not in this school.'

The child asks the teacher why staff are allowed to air an opinion, while a pupil is apparently barred from doing so.

Then the teacher states: 'I am not putting my opinion out. I am stating what is national school authority policy.'

The child tells him this is 'not scientific whatsoever', while the teacher tells him 'not every policy is scientific'.

The teenager said he did not have to be kicked out of class, which had wasted 30 minutes of his time, and the teacher tells him to 'make an official complaint'.

The pupil tells him: 'I was simply saying there are two genders – male and female. Anything else is a personal identification.'

The heated exchange was captured by the pupil after the 17-year-old claims he was kicked out of class at the Aberdeenshire school

The teacher tells the child he had made a point which was 'contrary to policy', and claims the pupil was 'making bad choices'.

At this point, the teenager voices his anger that the teacher had wasted his time, to which the teacher responds: 'I am not allowed to tell you how much of my time you have wasted.'

It is understood the teenager has been disciplined for sharing the video online without consent - rather than for the content of the clip - but the council declined to say whether the boy had been suspended.

The boy's family and the teacher both declined to comment last night. The viral clip – posted last Friday - generated thousands of 'shares' on social media platforms, with many of those commenting claiming that the teenager had been poorly treated.

In the US, one YouTube user made a film in which the child's experience was compared to George Orwell's classic novel 1984, about totalitarian brain-washing.

On Mumsnet, one user said: 'If I were a parent with a child at this school I'd be on the phone now to the school governors.'

But another Mumsnet contributor commented: 'If the teacher openly agreed with him, he would probably be sacked. They are in a tough position.'

Aberdeenshire Council (pictured, the authority's HQ) said the video did not show the full context of the incident

Last night Seamus Searson, general secretary of the Scottish Secondary Teachers' Association, said he did not have any knowledge of the case, but added: 'This sounds like a youngster looking for trouble.'

The local authority pointed to a legal duty for the public sector to have 'due regard' to certain 'protected characteristics' – including age, sex and 'gender reassignment'.

An Aberdeenshire Council spokesman said: 'As part of our Public Sector Equality Duty we aim to: eliminate discrimination, harassment and victimisation; advance equality of opportunity between those who have protected characteristics and those who don't; and foster good relations between those who have protected characteristics and those who don't.

'It is important to understand the context of any video clip taken without a person's consent. In our schools, fostering good relations among different groups can be a real challenge but our aim is to support a fairer, inclusive environment for all.'