British Transport Police were called to reports of a person on the line just before 6.15pm.
Officers attended alongside paramedics and the boy was treated on the scene before being taken to hospital in a critical condition.
A spokesperson for British Transport Police said: “Officers attended alongside paramedics and a 12-year-old boy from the local area was treated by paramedics.
“He was taken to hospital for treatment but despite best efforts, the boy sadly passed away this afternoon in the presence of his family. They are being supported by specially trained officers.
“Enquiries are on-going to establish how the boy came to be on the tracks but the death is not being treated as suspicious.
“A file will now be prepared for the coroner.”
Anyone with any information on this incident is asked to contact BTP by sending a text to 61016 or by calling 0800 40 50 40 quoting 412 of October 3.