Stuart Milne, 25, was confronted by officers in a field in Argyll and Bute while on a camping trip with his Boys' Brigade group after the girl's parents found evidence of the conversations, held over Skype.
Police were called in last July after the parents of the 12-year-old found "indecent" images on her tablet computer.
They found she had been taking part in online sex chats from the age of 11 and had sent pictures of herself naked and carrying out sex acts.
A forensic examination of her devices found that she had also received pictures from a man who was on her Skype contact list.
That led officers to Milne, who admitted taking part in the conversations and sending and receiving images from her over a 10 month period.
A sheriff told Milne she was concerned about him having contact with children and jailed him for two years.
Fiscal depute Susan Ruta told Dundee Sheriff Court: "The accused is single, resides with his parents and works for Tesco as a delivery driver. He and his father were at the time leaders in the Boys' Brigade.
"The complainer is a girl who was at the time in primary school. She had various electronic devices used to access the internet which she did in her room.
"On July 18 last year the complainer's parents discovered obscene images on her tablet.
"Police were contacted and various items were seized. A forensic examination revealed that the complainer had been engaging in sexualised chat using Skype."
She added: "Indecent images of the complainer were also found. Her contact list was interrogated and the accused was identified."
The police then obtained a search warrant for Milne's home but discovered he was on a camping trip with the Boys' Brigade in Argyll and Bute.
Because he was in contact with children at that point the police immediately made arrangements for officers from the then Strathclyde force to visit the camp and detain him.
Ms Ruta added: "His phone was examined along with his computer."
She said that explicit images involving the young girl were then discovered.
She said: "There were conversations between them taking place from October 2012 until June 2013 as well as video or voice calls logged."
Milne, 25, of Dundee, pleaded guilty on indictment to two charge under the Sexual Offences (Scotland) Act.
Sheriff Elizabeth Munro jailed Milne for two years and imposed two years' supervision upon his release.
In addition to this, he was also placed on the sex offenders register indefinitely.
Sheriff Munro said: "Only a custodial sentence is appropriate given the seriousness of the charges. I am seriously concerned about you being around young girls so on your release you will be placed on an extended sentence which means you will be subject to supervision."