A Fife man encouraged a 14-year-old boy to take part in a sex act while he watched online.
David Angus exchanged sexual messages with the youngster and got him to masturbate while a web camera was trained on him.
His wife discovered on-screen chat exchanges and messages as she went to use his tablet to play music.
Angus was told at Dunfermline Sheriff Court that children needed to be protected from adults who prey on them. He was handed a community payback order and put on the sex offenders register.
The 25-year-old of Blairadam, Kelty, previously admitted the offence committed on May 14 2015 at Blairadam Crescent, Kelty.
After discovering the sexual content Angus’ wife, believing the boy to be between 13 and 15 years old, spoke to her sister and police were contacted.
Police investigated and spoke to the boy, who said in the chat log he was 14.
Defence solicitor Alexander Flett said Angus’ family supported him and his wife accompanied him to court.
Sheriff Charles MacNair told Angus: “The offence you pled guilty to was of a very unpleasant and serious nature.
“In particular, having regard to the difference in age between you and the victim.
“In my view, it was quite clear to you that you were talking to a child but you continued.
“This sort of behaviour cannot be tolerated even where, as here, the child does not appear to have suffered any particular harm and he was encouraging you at points, because the fact remains he is a child and children require protection.
“Their naivety and immaturity cannot be preyed upon by adults.”
The order imposed will see Angus under supervision for three years and includes 135 hours of unpaid work and a four month restriction of liberty order.
He will be on the sex offenders register for five years.