Law enforcement fatalities hit a five-year high in 2016 with 135 officers killed in the line of duty, including eight killed in ambush attacks in Dallas and Louisiana in July that raised nationwide concerns, a study released on Thursday said.

So far this year, 21 officers were killed in ambush-style attacks, the highest figure in two decades, according to the study from the National Law Enforcement Officers Memorial Fund, which tracks data on the incidents.

This included five police officers gunned down in Dallas in July by a deranged US Army Reserve veteran, 25-year-old Micah X. Johnson, who said he aimed to avenge the shootings of black men by police nationwide.

"Public safety is a partnership and, too often, the service and sacrifice of our law enforcement professionals is taken for granted," said Craig Floyd, president of the fund.

Firearms-related incidents were the number one cause of death, with 64 officers fatally shot, the survey said. Traffic-related incidents accounted for 53 deaths.

Among the officers killed were local and state police officers, federal border agents and corrections officers. The study did not break out the number of police officers killed.

The average age of the officers who died on duty this year was 40 and the average length of service was 13 years. Texas had the most fatalities, at 17, followed by California with 10 and Louisiana with 9, including three who were killed in July in Baton Rouge, the survey said.

A black Iraq war veteran fatally shot the three police officers and wounded three others in Baton Rouge in an ambush.

The Dallas and Baton Rouge attacks, less than two weeks apart, followed fatal shootings by police officers of black men in Minnesota and Louisiana.

There were protests nationwide this year over the killings by police of unarmed black men, incidents that raised questions of racial bias in US policing.

The number of officers who died in the line of duty in 2016 was up 10 percent from the previous year of 123, the survey said.

Get the Monitor Stories you care about delivered to your inbox. By signing up, you agree to our Privacy Policy

"As we begin the new year, let us all resolve to respect, honor, and remember those who have served us so well and sacrificed so much in the name of public safety," Mr. Floyd said.

Reporting by Jon Herskovitz; Editing by Leslie Adler