A train driver was forced to dive to the ground to avoid being hit by another train travelling at 105mph, according to an official report.
The Virgin Trains East Coast driver took shelter next to his train with just three seconds to spare while he was on the track to investigate a power failure.
He escaped unhurt in the incident, which happened at Kyle Beck near Tollerton, North Yorkshire, shortly after 2pm on Wednesday August 3, while he was driving the 7.55am Inverness to London King's Cross service.
His dramatic escape was captured on CCTV by the oncoming train.
The report by the Rail Accident Investigation Branch (RAIB) stated that he had contacted the signaller to request that trains on adjacent lines should be stopped to allow him to safely inspect his train.
The signaller, who was a trainee, told the driver he would call him back, but this message was either misunderstood or not heard.
The report stated: "The driver and the trainee signaller did not reach a clear understanding about stopping trains on the adjacent lines, and the driver subsequently alighted from the driving cab of his train, incorrectly believing it was safe to do so."
He returned to his cab without incident but, shortly after leaving it for a second time to carry out a further inspection, he became aware of the oncoming train, possibly after its warning horn was sounded.
The report said he lay down close to his train "with three seconds to spare".
The RAIB concluded that the incident demonstrated the importance of signallers and drivers repeating messages back to each other and drivers remaining in their cab until they have received "positive confirmation" that adjacent lines have been blocked.