A railway worker narrowly avoided being hit by a train travelling at 85mph.
He became distracted while standing on a line near Shawford station in Hampshire, according to the Rail Accident Investigation Branch (RAIB).
After the driver sounded his horn and began the emergency brake procedure, the track worker moved clear of the train with one second to spare, stepping over two live electric rails to make his escape.
He was not injured but was "too shaken to respond" when a colleague asked him what had happened, the RAIB said.
He had been attempting to locate a rail defect when the near-miss occurred.
The investigation concluded that the man was "probably fatigued" due to sleeping in his car all week to avoid making long journeys to and from home each day.
The incident happened at 12.22pm on June 24 and involved a South West Trains service from London Waterloo to Portsmouth Harbour.
Investigators noted that a similar breakdown in safety discipline and vigilance occurred when a track worker died after being hit by a train as it approached Newark North Gate station, Nottinghamshire in January 2014.
Three new safety recommendations were made to Network Rail following the latest incident, including that managers consider the possible impact on their staff of long journeys before and after shifts.