Two teenagers waved to passengers as they clung on to a train underneath overhead electricity cables, a court has heard.

Harris Ahmed, 18, of The Warren, Manor Park, and a 16-year-old boy were both handed community orders today after posting video of themselves train surfing on YouTube.

They pleaded guilty at 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 TfL Rail train in Brentwood.

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

“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.

Ahmed 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.”

He added: “At one point in the video, you can see that the two boys foolishly lean above the train as it travels at high speed. This puts them dangerously close to the overhead power lines, which carry 25,000 volts of electricity. A disaster was very narrowly avoided during this stunt.

“I hope this sentence sends a very clear message that we will not tolerate this behaviour and we will work hard to identify offenders and bring them before the courts, in order to prevent and deter further offending of this nature.”