An investigation is under way into why a set of railway crossing barriers failed to operate on Tuesday night. A train was approaching Camborne station in Cornwall - where the main line crosses a busy road - when the barriers did not lower.
A signaller saw what happened and told the train driver to slow down and warn cars using his horn.
Network Rail says the fault has now been fixed.
Taxi driver Jim Geach saw the passenger train pass in front of his car at the level crossing.
He said: "The barrier lights came on, but the barriers failed to come down.
"A Virgin train coming down the track blasted his horn to warn vehicles that he was coming into the station.
"It was only good fortune that the signalman and the train driver acted very promptly to avoid a very serious situation."
Network Rail spokeswoman Morag Rickett said: "As soon as the local signalman saw that the crossing was not working he would have cautioned them across the crossing.
"He would have advised the drivers that the barriers had failed but the red road lights are still flashing and not to proceed over the crossing until it is safe to do so.
"The trains are also sounding their horns."
This is believed to be the first time such an incident has happened at the Camborne level crossing.
It is not known how long Network Rail's inquiry into the cause of the fault will take.
Drivers are being warned that they have to stop at a level crossing if they see warning lights, regardless of whether the barriers are working or not.