Updated

When protests erupted here over a black man’s killing during a struggle with two white police officers, Baton Rouge police officer Matthew Gerald made a promise to an old friend who urged him to be careful.

“I’m going to do what I got to do to keep you all safe, old boy,” Gerald told Dave Mulkey, his childhood friend and former roommate.

That text message was the last Mulkey received from Gerald before a lone gunman enraged by recent police shootings killed the 41-year-old rookie.

“That’s what Matt did. He went toward the danger, along with his fellow officers,” Mulkey told more than 2,000 mourners at Gerald’s funeral on Friday, the first for the three officers who were shot down before the attacker was killed.

Baton Rouge’s mayor and police chief hailed Gerald as a hero who proudly served his country during three tours in Iraq before joining the police force nine months ago.

The mayor and chief also issued broad appeals to respect police and heal wounds opened by the death of Alton Sterling, a black man whose shooting by police was videotaped and posted online, prompting widespread protests.

After 200 arrests in three days in Louisiana’s capital, tensions seemed to be easing before the surprise Sunday morning ambush.

Chief Carl Dabadie Jr.’s voice cracked as he strayed from his prepared remarks to respond to critics of policing. Departments across the country have been scrutinized after a steady stream of videotaped killings and mistreatment of black people.

“The media has blasted us for what we do and how we do it, basically portraying law enforcement as these band of bullies who go around and beat people up,” the chief said. “We’re not bullies. We are protecting our communities. And they throw us under the bus for it. And that’s wrong.”

Dechia Gerald, now a widow with two young girls, called him “my blue-eyed rock” in a written tribute, expressing hope that his legacy will “bridge the gap and foster peace in the country he lived, loved and died for.”