An internet troll who posted videos and messages mocking the deaths of teenagers, including a girl hit by a train, has been jailed.

Sean Duffy, 25, targeted Facebook tribute pages and posted videos on YouTube taunting the dead and their families.

Among his victims was Natasha MacBryde, 15, who died instantly when hit by a passenger train near her home in Bromsgrove, Worcestershire.

The day after Natasha's death in February, Duffy posted comments including "I fell asleep on the track lolz" on the Facebook tribute page created by her brother James, 17.

Four days later he created a YouTube video called "Tasha the Tank Engine" featuring her face superimposed on to the front of the fictional engine.

Duffy, who is unemployed and did not know any of his victims, pleaded guilty to two counts of sending malicious communications relating to Natasha.

He asked for three other cases of Facebook trolling – posting offensive messages on the internet – to be taken into consideration when he appeared before magistrates in Reading, Berkshire.

Jailing him for 18 weeks, the chair of the bench, Paul Warren, told him: "You have caused untold distress to already grieving friends and family.

"The offences are so serious only a custodial sentence could be justified."

He went on to say that the case served as an illustration of the "harm and damage" that malicious use of social networking sites could do.

Duffy was also given a five-year antisocial behaviour order to prohibit him from creating and accessing social network sites including Facebook, Twitter, YouTube, Bebo and Myspace. He will also have to inform police of any phone he has or buys that comes with internet access.

The court heard that Duffy has Asperger's syndrome and lived a "miserable existence" drinking alcohol alone at his home in Reading.

Joanne Belsey, prosecuting, said Duffy's series of online attacks began following the death of 16-year-old Hayley Bates, from Staffordshire, who died in a car crash in September 2010.

Duffy defaced pictures of her, adding crosses over her eyes and stitches over her forehead. One caption underneath a picture of flowers at the crash site read: "Used car for sale, one useless owner."

He then went on to focus on Lauren Drew, a 14-year-old who died from an epilepsy attack at her home in Gloucester in January.

Duffy posted offensive and upsetting images relating to her death and for Mother's Day created a YouTube video with a picture of a coffin saying "Happy Mothers Day".

Public schoolgirl Natasha MacBryde was his next target. She killed herself after she was sent a message by an anonymous bully on a social networking website. She had also been teased by members of an all-girl clique at school.

Duffy set up a fake tribute page on Facebook called Tasha the Tank Engine.

On the official memorial page set up by her brother James he wrote: "I fell asleep on the track lolz," and posted images of her with text saying she was spoilt. Other trolls joined the abuse.

Duffy's final target was Jordan Cooper, 14, from Washington, Newcastle upon Tyne, who was stabbed to death.

Duffy created a group called "Jordan Cooper in pieces" with a profile picture of a knife with blood dripping off it. A further YouTube video was also made which contained pictures of his eyes crossed out and slashes across his face.

Duffy's lawyer Lance Whiteford said: "In terms of mitigation there is none. I cannot imagine the trauma and anxiety caused to the families of these horrible, despicable offences."

She said his condition meant he was not aware of the effect he was having on his victims.

Duffy had been cautioned for a similar offence in 2009 and Whiteford said he lived an isolated life and had himself been bullied at school and work.

Speaking outside court, Natasha MacBryde's father, Andrew, said: "He is a disturbed individual who caused the maximum of grief for his own satisfaction.

"I think he must be a very lonely man who unfortunately tried to get attention through the most disgusting way possible.

"In a way I feel sorry for him and I think he needs some sort of counselling as it is obviously very odd behaviour.

"I hope his sentencing shows other trollers that they are not anonymous and they will be caught if they continue their vile games."

He said he had not been able to watch the Tasha the Tank Engine video as it was too distressing. Following the sentencing, Lauren Drew's father Mark spoke of the devastation it caused her family as they struggled to come to terms with her death: "We were already having a hard time. Lauren was my only daughter and I worshipped the ground she walked on and this person was hiding behind a computer.

"He caused devastation to us and other families; for so many people. It hurts but he sits behind a computer with no feeling."

Drew called for the operators of social networking sites to take more responsibility for their content: "The web is a wonderful thing if used right but as you can see in this case it was used wrongly. These days children live on Facebook, it's their lives and they're just so vulnerable."

After the hearing police said they would continue to track down offenders like Duffy.

Det Ch Insp James Hahn, of Thames Valley police, said: "Clearly this has been a very emotive case, that has caused additional distress and suffering for families who have been trying to cope with the loss of loved ones.

"Malicious communication through social networking is a new phenomenon and unfortunately shows how technology can be abused. However, our investigation shows that offenders cannot hide behind their computer screens."