A Baton Rouge police officer has been remembered as a hero by the city's mayor, who urged people to respect the police and avoid the "us vs them" mentality that can encourage violence.
More than 2,000 people packed into the church where Mayor Kip Holden and other leaders paid tribute to Matthew Gerald, the first of three officers killed by a lone gunman to be laid to rest.
"The men and women who put on those uniforms, they respect you. Respect them," the mayor said.
Baton Rouge police chief Carl Dabadie Jr.'s voice cracked as he strayed from his prepared remarks to respond to the criticism police across the country have received over a steady stream of videotaped killings of black people by police.
"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," he said.
"We're not bullies. We are protecting our communities. And they throw us under the bus for it. And that's wrong."
Two of Mr Gerald's uniforms hung next to his flag-draped casket as photos on a big screen showed moments from his 11 years in the military, his fledging 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 killed by Gavin Long, an Army veteran who urged violence in response to what he saw as the oppression of black people.
After killing three officers and wounding three more on Sunday, Long was killed with a long-distance shot by a Swat team officer.
Police said the attack shattered days without significant violence in Baton Rouge, even as thousands protested amid heightened racial tension following the police shooting of Alton Sterling, a black man whose death was recorded and posted online.
The two officers involved in Sterling's death were put on administrative leave and the US Justice Department is investigating, but the streets have been busy with people demanding an end to police shootings of black men.
The funeral speakers included Mr Gerald's childhood friend Dave Mulkey, who described sending him a text message during the protests over Sterling's death.
"I told him to be careful, and to keep a cool head," Mr Mulkey recalled.
He said Mr Gerald's response was: "I'm going to do what I got to do to keep you all safe, old boy."
Mr Gerald joined the Baton Rouge Police Department less than a year ago, an enthusiastic rookie at age 41, after serving four years in the Marines and seven years in the Army, where he did three tours in Iraq and ran a Blackhawk helicopter crew.
He was partnered with Corporal Lester Mitchell, an 11-year police veteran. The two officers, black and white, 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," Mr Mitchell said on Friday.
Mr Gerald, he said, "was a protector, it was just in his DNA".
He said they were writing reports at police headquarters on Sunday when Mr Gerald said he was going for an energy drink at the B-Quick convenience store a few blocks away.
Someone at the store approached Mr Gerald, saying an armed man was walking through the area, Mr Mitchell said.
Mr Gerald radioed for help, and Mr 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 on Friday included Sheriff's Captain 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," Mr Cox said. "We hope this isn't some trend."