Two teenagers waved to passengers on a rail platform as they clung on to a train underneath overhead electricity cables in Essex, a court heard.

Harris Ahmed, 18, and a 16-year-old boy were sentenced on Monday after posting video of themselves “train surfing” on YouTube.

They each pleaded guilty at north London’s Highbury Corner Magistrates’ Court to endangering the safety of a person conveyed by the railway.

British Transport Police said the footage, reported to them on October 31, showed youngsters on a train in Brentwood, Essex.

Prosecutor Chiram Mondal said: “This is an offence effectively called train surfing.

%image(15363637, type="article-full", alt="Mobile phone footage grab issued by British Transport Police of Harris Ahmed, 18, about to climb between two train carriages, as he and a 16-year-old boy (who cannot be identified) were sentenced after posting a video of themselves "train surfing" on YouTube. Picture: BRITISH TRANSPORT POLICE/PA WIRE")

“The two defendants posted a video on YouTube where they were identified as jumping on a train and filming themselves riding between the two carriages.

“They are seen to wave to other people on the platform effectively as some form of stunt.”

He pointed out that “the most danger was to the defendants themselves” as their arms were very close to the edge and beneath high voltage cabling which could fall down and electrocute them.

If the train had to stop quite suddenly it could have “a detrimental impact” on the passengers, Mr Mondal added.

%image(15363638, type="article-full", alt="Mobile phone footage grab issued by British Transport Police of Harris Ahmed, 18, prior to to climbing between two train carriages, as he and a 16-year-old boy (who cannot be identified for legal reasons) were sentenced after posting a video of themselves "train surfing" on YouTube. Picture: BRITISH TRANSPORT POLICE/PA WIRE")

Ahmed, a student, of Manor Park, east London, was given a 12-month community order, while the 16 year-old, who cannot be named for legal reasons, was given a four-month referral order.

They were each ordered to pay £105 in surcharge and court costs.

Ahmed has since deleted the video of the prank, the court heard.

After the hearing BTP inspector Steve Webster said: “These pranksters risked their lives in making this reckless YouTube video. It isn’t impressive, it is stupid.

“I am stunned that people still think that so-called train surfing is a clever idea, when every day our force sees tragedy on the railway.

“The last thing we ever want to do is visit a family to inform them their loved one has been killed by dangerously climbing on top of a train or otherwise trespassing on the railway.

“The railway is a dangerous environment and can be fatal.”