It had travelled less than 100 metres when the driver sensed the detaching engine and applied the emergency brakes to stop it.
The engine had detached at a flat area. Had it occurred at a slope, a serious accident could have happened, an official said.
The technical officer of the train re-attached the engine to the wagons and brought it back to the Hatton station.
The railway authorities had arranged a separate train to take the passengers to Badulla from Hatton.