Glenn Telfer claims he was the top candidate for a permanent post at an Edinburgh primary after doing the job for several months and earning plaudits from parents and his boss.
But the 55-year-old ended up out of work after the job went to Louise Hunter, 25.
Mr Telfer is taking Edinburgh City Council to an employment tribunal claiming sex and age discrimination.
He told the hearing in Edinburgh that he began his teaching career in 2005 after caring for his daughter, now 18, who has cerebral palsy and epilepsy.
He said he was a supply teacher for a P4 class at Cramond Primary last year.
He told the hearing that he was praised by headteacher Una Gillespie, who “said that she had never seen pupils like a teacher the way they liked me”.
“Before the end of term, Mrs Gillespie said she would like me to stay on and teach primary five, the current P4 class, in the next academic year,” he added.
Mr Telfer said he returned to the classroom in August last year as a supply teacher but staff illness meant the full-time post was advertised.
He made the shortlist of seven candidates but, despite already teaching the class, lost out to Ms Hunter and left a week later.
“Men just never seem to get a job,” he told the hearing.
“The school does employ men but they hold positions such as a janitor. When I was there, I was the only male teacher in a school of over 30 women.
“I believe that the discrimination was evident at the interview process when I was told I would only be getting an interview due to the fact I was already working there.”
He added: “Quite a few people had said that if I was a young woman I would have got the job.
“It’s not about men working in the school, it’s about being able to work as a teacher.”
Mr Telfer said he received messages of support from parents when they were informed he would be leaving the school.
He said: “I received e-mails through Facebook from parents trying to get the decision to remove me reversed.
“The e-mails said things like ‘It’s great having a male teacher as it brings balance to the school’, ‘You were a role model for children’, ‘Mr Telfer is an inspiration’.
Mr Telfer said his professional development folder showed examples of helping children in class, and raising their grade standard and their overall confidence in their own ability.
“I also worked with children in learning support,” he said. “There was a child who would lose his pen and cry or lose his seat and become upset. I made great progress with this child.
“I implemented a programme of positive behaviour where pupils were rewarded for things like cleverness, kindness and sharing.
“I wrote home to the parents of kids to tell them of their progress for the work that merited recognition.
“The parents would also write and get in touch with me saying they noticed their child was expressing a keenness about school they never did before I started working there.”
Mrs Gillespie, who was present at the tribunal, declined to comment.
The hearing continues.
An online petition created by parents of children at Cramond Primary gives Mr Telfer support. One mother, Claire Campbell, wrote: “Mr Telfer is a positive role model for the children. A good, male primary teacher is a bonus to any school and I feel Cramond has squandered an excellent opportunity.”
Only around eight per cent of primary teachers are male. A recent study of more than 800 men commissioned by the Training and Development Agency (TDA) looked at the impact of male primary teachers in boys’ development and argued the case that male teachers are essential for providing young boys with role models in their lives.
The TDA found that 35 per cent thought that a male teacher challenged them to work harder.