For most of the last 35 years, the number of police officers who die on the job in the U.S. declined, but one grim statistic held steady: The most common cause of death was gun homicide. Those numbers grew significantly on Thursday night when five police officers were shot and killed at a demonstration in Dallas that was protesting recent killings by police officers in other states. President Obama called it “a vicious, calculated and despicable attack on law enforcement.”

Per officer, policing had become even safer in recent years than the overall death counts suggest, which makes the Dallas shooting that much more of a singular, horrific massacre. That’s because the decline in the number of deaths by police officers in the line of duty has occurred as the number of officers has risen. The number of full-time, sworn local police officers increased by 35 percent from 1987 to 2013, according to the Bureau of Justice Statistics. During that same period, the number of officers killed declined by 34 percent. And a growing share of officer deaths are happening in accidental or deliberate car collisions.

Our data for on-duty police officer deaths comes from the Officer Down Memorial Page, started in 1996 by a college student who is now a police officer and who continues to maintain the database. It extends much further back than the Federal Bureau of Investigation’s data — all the way back to 1791, when two officers were killed, both in New York state. (It hadn’t yet been updated with the Dallas shootings as of Friday afternoon.) National data on the number of police officers isn’t available that far back, but the rate of police officers per the overall population has declined significantly over the years.

Today’s patrol cops have a dangerous job, but not one of the deadliest ones in the country. Police and sheriff’s patrol officers’ death rate per 100,000 full-time workers was 13.5 in 2014, according to the Bureau of Labor Statistics — nearly four times the rate for all workers but below the rate for dozens of other professions, including pilots, truck drivers and loggers.

The five police officers who died in Dallas are among the largest number killed in a single incident in U.S. policing history. It’s the deadliest incident for the police since 72 officers died in the Sept. 11, 2001, terrorist attacks, according to the National Law Enforcement Officers Memorial Fund. And the five officers who died in Dallas are the largest such number killed in a single shooting incident in the U.S. and its territories since seven police officers in Puerto Rico were killed during a political revolt in 1950. The last shooting of police officers in the U.S. that was deadlier than Dallas was an attempted arrest at a Missouri farm in 1932, in which two suspected car thieves shot and killed six officers.

You can download the data used for this article on GitHub.

Ben Casselman contributed research.