It happened at the Brasswell crossing on the outskirts of Dumfries in January and the line had to be closed for a period afterwards until it was checked out.
In court on Tuesday, van driver James O’Brien, 21, pleaded guilty to a charge of driving carelessly at the crossing and failing to comply with the audio and visual warning signals of a train approaching.
Fiscal depute Alison Herald said the large white van had been seen passing the window of a house near the crossing at 9 am and the audio alarm went off and then a bang was heard – and another.
Meanwhile, the driver of a train just 400 yards away saw the van approach the crossing and put on the brakes as it went over the lines and hit the barrier, but managed to avoid any of the debris.
Solicitor Carolyn Priestley said O’Brien, of Shakespeare Street, Dumfries, used the crossing regularly and on this morning was driving into the sun and didn’t see the red light.
However, he couldn’t explain how he did not hear the audio alarm.
She added that the van was well clear before the train reached the crossing.
He had later telephoned the police himself and reported the incident.
O’Brien was fined £300 and had six points endorsed on his licence.