A 34-year-old man dated a teenager half his age and then threatened to publish a sex tape of them online when she dumped him.
Paul Culbert sent a series of text messages to try and blackmail his 17-year-old victim, who cannot be named for legal reasons, into rekindling their nine-month relationship.
He threatened to post a sex video they had recorded together on a social networking website, Cupar Sheriff Court in Fife heard.
Prosecutor Joanne Smith told the court: 'The complainer decided to end the relationship and on telling Culbert of her decision she started to receive numerous calls and texts to her phone.
'The text messages were an attempt to blackmail her into reconciling their relationship, or the video would be uploaded onto a social networking site.'
The girl did not return any of Culbert's texts or phone calls, which were made between July 7 and 9 this year, and contacted police.
Culbert, from Leven, Fife, was arrested and his laptop and mobile phone seized.
He pleaded guilty to sending text messages that were grossly offensive or of an indecent, obscene or menacing character, making offensive comments, and threatening to distribute a video of a sexual nature.
The court heard that Culbert accepted that he may have sent texts which 'were a bit over the top'.
Sheriff Charlie Macnair today ordered Culbert to perform 165 hours of unpaid work and to pay his victim £250 for her 'distress'.
He must also delete every image and video of her, including the sex tape, from his computer hard-drive.
Sheriff Macnair told Culbert: 'These texts you sent were no doubt extremely distressing to the complainer. The threat of sending or distributing a video of this sort is in my view extremely serious.'
Culbert has to present his laptop to social workers within 24 hours of getting it back from police, who have been holding it since his arrest in July, to prove that the video - and any other 'portrayal' of the girl - has been erased.
He was also ordered not to even watch the video again before wiping it - and not to distribute it.
Sheriff Macnair told the hearing that he had no powers to confiscate the laptop but told Culbert he would not get back the smartphone on which he recorded the sex tape.
Leaving court, Culbert said: 'I will be deleting the video. I’m just glad this is all over.'