When a shooter began firing on two Baton Rouge police officers in a July ambush attack, Deputy Sheriff Brad Garafola managed to take cover behind a dumpster. After calling in the attack on his radio, however, Garafola left his covered position, charging into the street to help the wounded officers.

The shooter, armed with an assault rifle and a semi-automatic pistol, kept on firing, killing Garafola, Corporal Montrell Jackson and Officer Matthew Gerard.

"He left a safe position to help someone else," said Tonja Garafola, Brad’s wife.

From left, Baton Rouge police officer Matthew Gerald, Montrell Jackson, and East Baton Rouge Deputy Sheriff Brad Garafola Baton Rouge Police; East Baton Rouge Sheriff's Office

And he would do it again. "You never leave a man behind," she said.

Garafola is one of 64 officers shot and killed in the line of duty this year. Twenty-one of those officers were killed by ambush attacks targeting police, according to new data from the National Law Enforcement Officers Memorial Fund, up from six in 2015.

The numbers show an increase in total officers shot and killed — a 56 percent spike since last year — and a 250 percent rise in ambush fatalities.

The extreme spike in ambush figures appears especially large because the incidents are typically so rare.

The 2016 rise in police officer deaths comes in the same year as highly publicized fatal police shootings of African American men drew large protests, media scrutiny and alarm from activists concerned over what they perceive to be excessive use of force by police against people of color.

A member of Baton Rouge police Cpl. Montrell Jackson's unit kneels and touches his casket during his funeral service at the Living Faith Christian Center in Baton Rouge, La., on July 25, 2016. Patrick Dennis / Baton Rouge Advocate via AP, file

"It’s the worst year we’ve had in terms of shooting deaths in five years," said Craig Floyd, CEO of the Memorial Fund, adding that ambush attacks are at a 20-year high.

Related: Baton Rouge Community Says Goodbye to Slain Police Officer

The sharp rise has left families and fellow officers distressed and on edge. NBC News interviewed dozens of relatives and colleagues of officers killed on duty this year as they attempted to cope with their loss and make sense of how these types of attacks have played out on social media.

"It’s sad to think that our officers are being targeted simply because of the uniforms they wear and the job that they do," Floyd said.

"I love this city but I wonder if this city loves me"

One of the other officers killed in the Baton Rouge ambush, Corporal Montrell Jackson, poured out his feelings about community tensions with police on Facebook — just nine days before he was killed.

Baton Rouge Police Officer Montrell Jackson, holds his son Mason at a Father's Day event for police officers in Baton Rouge, Louisiana in 2016. Trenisha Jackson via AP

"I swear to God I love this city but I wonder if this city loves me," Jackson wrote. "In uniform I get nasty hateful looks and out of uniform some consider me a threat."

Jackson, a black officer, posted the note a few days after Baton Rouge police shot and killed a black men, Alton Sterling, outside a convenience store. Videos of the fatal incident went viral, sparking protests and inflaming tensions between the community and its police.

Jackson invited protesters and officers alike to come share hugs and prayers when they saw him on patrol.

"I personally want to send prayers out to everyone directly affected by this tragedy," he wrote, "please don’t let hate infect your heart."

Related: Uncle of Slain Officer: 'He Loved Baton Rouge'

His widow, Trenisha, called Jackson her "Superman."

Trenisha Jackson reacts during the funeral of her husband Montrell Jackson at Greenoaks Memorial Park in Baton Rouge, Louisiana on July 25, 2016. Jonathan Bachman / Reuters

"My goal is just to keep his legacy and his vision alive. I want to make sure that my husband did not die in vain," she said, adding that she often returns to the words he shared on Facebook.

"I have to remind myself, ‘Trenisha, don’t let hate infect your heart,’" she said. "Those was my husband’s words so I just, you know, try to live by that."

The third officer killed in the ambush, Matthew Gerald, had joined the force this year after serving three tours of duty in Iraq.

Matthew Gerald, 41. Baton Rouge Police Department

"He was already a hero before he even became a Baton Rouge Police Officer," said Gerald’s older brother, Marc. "Looking back, he always wanted to play cops and robbers, and he always wanted to be the cop."

According to Marc, Gerald's wife learned she was pregnant a week after her husband died. Gerald also left behind a daughter and a step-daughter.

"I’m going to be in their lives as much as possible," Marc says, "but the fact that they’re growing up without a father is tough for us to think about."

"You think he's safe"

Gerald wasn't the only former soldier to face lethal danger at home this year.

Sheriff’s Deputy Mark Logsdon, an Iraq War Army veteran who remained in the Reserve, responded to a February house call with Deputy Patrick Dailey, a U.S. Marine, where a suspect opened fire, killing them both.

"Mark was a hero," said Logsdon’s mother, Debra. Authorities told her the killer had stockpiled weapons and ammunition, and might have killed more people had police not intervened.

"You think he’s safe," she said, remembering that winter day in February when she received the call that her son had been shot. "Police officers are caring; they’re loving; they have families."

Related: Slain Harford Sheriff Deputies Remembered as 'Heroes'

Other military families said combat experience strengthens an officer’s resolve.

Tammie Jacobs, whose son Allen Lee Jacobs was killed on a patrol in March, recalls how he persevered through 15 months in Iraq and a harrowing 2014 incident while serving on the Greenville Police Department.

He had been run over by a car while on duty, and Jacobs says she thought back to that event this March, when she walked into a “room of people crying” at the hospital.

“I’ve been through this before,” she says, “I never expected he would die. I just thought well he's going to be really, really angry if he's injured and not going to be able to be a police officer.”

Officer Jacobs was shot and killed by a 17-year-old gang member, who then committed suicide when officers surrounded him.

Jacobs sees parallels across her son’s service.

“He lived in the neighborhoods in Iraq, just like was a neighborhood cop here, trying to keep the people safe,” she says.

Patrick Zamarripa served three tours in Iraq before joining the Dallas Police Department. He was among five officers killed in an ambush attack in July. The officers had been protecting a Black Lives Matter protest that wound through downtown.

Zamarripa's brother, Carlos Zamarripa, said he always downplayed the risks of his work for his family.

"He never let my mom and my sister really know the dangers of his job," Carlos said. "He’d always say, ‘I don’t want them to worry about things I do out there. I’m doing something good, that’s all you gotta know."

In Kansas City, it was the military experience of Police Captain Dave Melton that led to a somber assignment — writing an official manual for officer burials.

The department had not lost an officer in the line of duty in 18 years, but when Detective Brad Lancaster was killed in May, Kansas City Police Chief Terry Zeigler tasked Melton with planning a proper burial.

"I said, ‘Dave, here’s the deal, buddy. I need you to put together a manual ... so we have a playbook to go by if this should ever happen again but, God forbid, after we’re long gone,’" Zeigler said.

Zeigler said Melton helped the department conduct a "phenomenal" service for Lancaster, who was shot while pursuing a suspect on foot.

Melton was fatally shot in the head while searching for a suspect in a drive-by shooting just ten weeks after Lancaster’s funeral.

Kansas City, Kansas, police captain Robert David Melton. KSHB

"The first funeral service we used [his manual] on after he wrote it," Zeigler said, "was his own."

Lynn Melton, Melton’s sister-in-law, says she "never dreamed in a million years" she would get the phone call.

"It was just surreal," Lynn Melton said. "In my mind, I wanted to think, he’s ok, but in my heart I knew he wasn’t, because he always wore his vest."

Zeigler said the killings have reshaped how he approaches his officers.

"If you would’ve told me, at some point in my career, I would be hugging cops and telling them that I love them, I would’ve told you, you’re crazy!" he said. "But I have hugged more cops, and told more cops that I love them, this year than I ever would’ve thought in a million years."

Many families feel especially protective of those who serve.

Shannon Frazier is raising a three-year-old and a thirteen-year-old after their father, De'Greaun, was shot and killed in August, working an undercover drug operation.

“People talk so negative about law enforcement, but are you going to get out there and do it?” she asks. “Are you willing to take that oath, take that badge and that gun and put your life on the line to protect people that you don’t even know?”

Emily and John Garafola, right, parents of East Baton Rouge Sheriff deputy Brad Garafola weep after being presented with a flag at the Istrouma Baptist Church in Baton Rouge, La., on July 23, 2016. Hilary Scheinuk / Baton Rouge Advocate via AP

"It's not localized"

Fred Bealefeld, a former Baltimore police commissioner, said social media magnifies reactions by officers and citizens alike to tragic incidents involving police.

"It’s not localized," he said. "A funeral or a killing of a police officer in Maine is viewed by police families and police officers all across the country."

"The instantaneous nature of their exposure to these incidents puts a psychological strain on police officers, all over the country," Bealefeld said, "that no one in law enforcement has ever had to deal with before."

Community reactions get nationalized as well.

"If we did something wrong in Baltimore, we prepare for the backlash in Baltimore," Bealefeld said. "But now, something that happens in Stanford could blow up in Baltimore."

Some families of fallen officers also questioned how to evaluate what they see online.

"I don’t know if it's through Facebook, or if there truly is an increase in the amount of police violence," said Amy Gooding, whose husband Jason, a Portland officer, was killed while serving a warrant in February.

While the internet certainly enhances the availability and intensity of information, law enforcement leaders stress that the numbers show police currently face an unusually high threat.

"You’d have to go back almost to the 1970s, to see a similar experience in American policing," Bill Bratton, who just finished his second stint as New York Police Department Commissioner and provides police analysis for NBC News, said. "A significant number of those who were killed in the line of duty by gunfire were actually targeted because they are police."

To support or learn more about officers killed in the line of duty this year, readers may consult these websites:

C.O.P.S.: Concerns of Police Survivorshttps://www.nationalcops.org/

Officer Lesley Zerebny Memorial page, provided by Zerebny family:https://www.gofundme.com/2tejkxwk

Patrick E. Zamarripa Foundation page, provided by Zamarripa family:https://www.facebook.com/pg/Patrick-E-Zamarripa-Foundation-216745682087681/about/