An investigation has been launched after a freight train laden with fuel derailed and burst into flames as it crossed a bridge.