Nationwide, 21 law enforcement officers were killed in such attacks, including the five officers fatally shot July 7 in downtown Dallas. It was the highest number of ambush deaths in more than 20 years, according to a preliminary report by the National Law Enforcement Officers Memorial Fund.

Only eight officers were killed in ambushes in 2015.

In total, 135 officers were killed in the line of duty last year, according to the report. Sixty-four of those officers were shot, the report says.

"We've never seen a year in my memory when we've had an increase of this magnitude in officer shooting deaths," Craig Floyd told The Associated Press. Floyd is president and chief executive of the National Law Enforcement Officers Memorial Fund. "These officers were killed simply because of the uniform they wear and the job they do."

Twenty officers were killed in multiple-shooting death incidents, which tied 1971 for the most killed in such incidents since 1932, the report says. Those multiple-shooting incidents include the Dallas ambush and the fatal attack of three officers in Baton Rouge, La., 10 days later.

Micah Johnson opened fire on officers in downtown Dallas at what had been a peaceful protest of police shootings of black men around the nation. Johnson fired into the crowd around 9 p.m. July 7 on Main Street near Lamar Street. He killed five officers and injured nine others, as well as two civilians.

"In 2016, our department suffered extreme tragedy. The events of July 7th will forever mark this year as one we will never forget," Interim Dallas Police Chief David Pughes said in a written New Year's Day statement. "The unbelievable show of support from our community gave us strength to continue on."

Photos of the five officers killed in the July 7 Dallas ambush were on display during an interfaith memorial service at the Meyerson Symphony Center. The victims were (from left) Michael Krol, Brent Thompson, Lorne Ahrens, Michael Smith and Patrick Zamarripa. (File Photo/Smiley N. Pool)

Texas had the highest number of officer fatalities, with 17. The report tracks line-of-duty deaths, including shootings, vehicle crashes and job-related illnesses.

Gun violence was the top cause of law enforcement deaths in 2016. Typically, traffic-related incidents are the No. 1 cause of officer deaths.

Though the number of officers shot and killed in the line of duty rose last year, the number of people shot and killed by police dropped, according to The Washington Post. The newspaper tracks fatal police shootings and found that 957 people were killed by police in 2016, down from 991 in 2015.