The train made an emergency stop after the reptile was spotted lurking on a baggage rack in a carriage headed to Jakarta from Bogor, south of the capital.
Smartphone footage, which quickly went viral, showed the bespectacled man casually snatch the snake's tail and then smash its head on the floor in a violent whipping motion.
The creature was apparently killed instantly as shocked spectators -- including a baton-wielding transit security officer -- kept their distance.
It is not clear what kind of serpent it was, nor whether it was venemous. No injuries to passengers were reported.
More From This Section
Train operator KCI said the reptile is thought to have slithered out from a passenger's bag.
"We regret the incident and apologise to train travellers who were disturbed by it," spokeswoman Eva Chairunnisa told AFP.
It is not uncommon to see livestock or pets travelling on public transport in rural Indonesia, but passengers are prohibited from taking animals on urban transport lines.