This July 24, 2009 file photo shows the scene inside the Van Ness-UDC Metro station in Washington, where a person was hit by a train going in the direction of Shady Grove. (Kenneth W. Smith Jr./The Washington Post)

More than 300 times last year, people walked onto railroad tracks to intentionally put themselves in the path of a train — and in 266 cases they successfully committed suicide.

That data, recorded by the Federal Railroad Administration, is based on the conclusions of state or local police who investigated each case. The number of what’s known as “suicides by rail” is the lowest in seven years, and preliminary data from the first four months of 2018 suggest the annual figure may end up being far lower than last year.

While deaths ruled as suicides have declined, the number of trespassers killed by trains is higher than it has been in 20 years.

The suicide numbers and the total number of “trespasser” deaths and injuries on rail lines — 1,017 last year — reflect that it’s virtually impossible to keep people from wandering onto the country’s 137,465 miles of freight railroad lines, and that the industry has had mixed success in using warning signs and barriers to scare trespassers away.

Rail beds are private property, but some people are attracted to them because they offer an easy path that cuts through neighborhoods or, in rural areas, passes through fields or forests.

“If you are walking close to railroad tracks, avoid distractions and be sure to put down the phone, or remove your ear buds because you may not hear a train approaching,” said AAA Mid-Atlantic spokesman John B. Townsend II, whose office issued a report Tuesday on trespasser deaths in the Washington region. “Even if the locomotive engineer sees you, a freight train moving at 55 mph can take a mile or more to stop once the emergency brakes are applied. That’s the length of 18 football fields.”

The data Townsend compiled shows that 126 people have been killed on railways in the District, Maryland and Virginia since 2012 — an almost equal number in Maryland (60) and Virginia (62), and four in the District.

Those numbers are skewed, however, because Congress has exempted the D.C. Metro, New York’s subway, and most other subways and light-rail systems from filing trespassing or suicide data with the FRA.

Townsend said his review of data from Metro and news reports found there were at least 20 suicides by rail on the system between 2011 and 2015.

Overall, in 2016, the Congressional Research Service reported, there were 485 trespasser deaths, 492 trespasser injuries, and 229 suicides on freight, commuter and intercity passenger railroads.

People bent on suicide have been profiled by the FRA in an effort to understand and minimize the number of fatalities.

A report conducted for the 2007-2010 period found that:

• All of those who died had abused alcohol or drugs, and all but two suffered from mental illness.

• At the time they stepped in front of a train, half had consumed alcohol or illegal or prescription drugs.

●• 84 percent of those who committed suicide were men.

• The median age was 40 years old.

• More than half suffered from a chronic physical illness that often caused pain.

“Choosing a violent method, such as suicide by rail, has been associated with substance abuse or dependence and psychotic disorders,” said another FRA report published four years ago. “The individuals included in this report were more likely to have a mental disorder (96 percent) or a drinking (62 percent) or substance abuse (58 percent) problem than individuals who chose other suicide methods.”

In some cases, despondency is caused by a triggering event or a series of events, the 2014 report said.

“To a person who has become vulnerable to suicide, the event or set of events triggers the suicide. Existing research on suicide attempters cite precipitating factors including academic stress, chronic physical illness, death of a loved one, economic distress, family and intimate partner relationship problems, occupational stress, substance abuse, and unemployment,” the study said.

It found that in 35 percent of the cases the suicide victim feared “an upcoming negative or humiliating event, such as a court hearing, an expectation of incarceration, or loss of custody of children. Additionally, it was found that 15 percent had experienced the dissolution of a relationship with a significant other in the weeks or months prior to their death.”

Almost half of the people who committed suicide on the railroads had attempted suicide of some form at least once in the past, and some had attempted it multiple times

Suicide by railroad make up a tiny fraction of those who kill themselves in the United States. In 2014, for example, 42,773 people committed suicide — about half using a firearm — while only 275 succeeded in doing so by stepping in front of a train.

The Congressional Research Service reports that “Although the freight railroads, Amtrak, and many commuter railroads have police forces that could arrest trespassers, the industry has devoted most of its effort to educating the public that railroad tracks are far riskier than they appear.”

To that end, Congress and the rail industry have funded a nonprofit group known as Operation Lifesaver to educate people about the dangers of grade crossings and trespassing.

The 2014 FRA study differentiates between those who trespass on rail lines and those who plan to take their own lives.

“Reducing the overall number of individuals who attempt suicide by all means will likely result in a decrease in suicides on the railroad rights-of-way,” the study says.