BATON ROUGE, La. -- 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' 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.
Mayor Kip Holden said people must avoid an "us versus them" mentality and recognize that police officers are "here for all of us."
"The men and women who put on those uniforms, they respect you. Respect them," Holden said.
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."
Gerald's Army and Marine uniforms hung next to his flag-draped casket as photos on a big screen showed moments from his 11 years in the military, his fledgling police career and his family life.
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."
Funerals for sheriff's deputy Brad Garafola and police officer Montrell Jackson are set for Saturday and Monday. They, too, were slain by Gavin Long, an Army veteran from Kansas City, Missouri, whose rambling videos urged violence in response to what he considered oppression.
Gerald joined the Baton Rouge police as an enthusiastic rookie after four years in the Marines and seven years in the Army, where he served as a Blackhawk helicopter crew chief.
J.D. Leach, commander of the police academy, recalled asking Gerald why he was joining the force at his age.
"I've been serving my country and now it's time to serve my community,'" Leach recalled Gerald telling him.
Gerald was partnered with Cpl. Lester Mitchell, an 11-year police veteran. The two officers, white and black, began riding together on July 1, days before Sterling's death.
"We talked about the madness, how much it was putting a strain on the community, police relations," Mitchell said during an interview before the funeral.
Mitchell said they were writing reports at police headquarters Sunday when Gerald said he was going for an energy drink at the B-Quick store less than a mile away.
Someone at the store approached Gerald, saying an armed man was walking through the area, Mitchell said. Gerald radioed for help, and Mitchell was among the officers who raced to the scene, hearing gunfire as they arrived.
"We were right in the middle of the firestorm," he said. "He had already been shot when we got there."
The many mourners Friday included Sheriff's Capt. Tom Cox from Knox County, Tennessee. He said he attended all five funerals for the officers killed by a sniper in Dallas this month, and planned to attend all three of the funerals in Louisiana.
"It's numbing, with this many in such a short period of time," Cox said. "We hope this isn't some trend."