Duncan Maclean, 75, had his trousers down and performed the act for around two minutes.
His antics sickened a fellow passenger, who confronted him.
A judge at South Tyneside Magistrates’ Court heard Maclean, of Otterburn Terrace, Jesmond, Newcastle, had been drinking alcohol and had taken sleeping drug temazepam beforehand.
But the court was told he had committed three other sex offences, all in or around 2015 – and alcohol was a factor.
Prosecutor Gurjot Kaur said they for outraging public decency, a sexual assault and exposure, one of which had led to a suspended prison sentence.
Deputy District Judge Gary Garland spared Maclean jail but told him he would have been caged had he been half the age he is.
He instead handed him an 18-week sentence, suspended for two years.
But he warned: “If this was someone who was 30 or 35, I’d have no hesitation in sending you to prison, probably for about four months.
“If within the next two years you do something like this again, you can almost guarantee, and it doesn’t matter if you are 76 or 77, there’s little alternative than of you being sent to prison.
“There comes a point when the courts can’t do anything else to protect the public than to take you out of circulation.”
Ms Kaur said the incident happened on a busy carriage, where the defendant had “his hands down his pants and his trousers down”.
Andrew O’Hanlon, defending, said his client had been at an archaeology site, which was his hobby.
“He had been out in the sun and taken some libation, too many, and some temazepam. He was a dead offering when the police lifted him,” said the solicitor.
“I think the sun and intoxication and drugs have played a part in this offence.
“He hasn’t done anything for a year, so perhaps he’s learnt to control himself.”
Maclean pleaded guilty to outraging public decency.
As a condition of the suspended sentence, he must complete up to 40 days of rehabilitation work with the Probation Service.
He must also abide by a three-month, 8pm to 8am electronically monitored curfew, and pay a £122 victim surcharge and £85 court costs.