Three police officers were shot dead and three others wounded in Baton Rouge on Sunday, less than two weeks after a black man was killed by police in the Louisiana capital, sparking nationwide protests and the killing of five policemen in Dallas as racial tension mounts.
The Baton Rouge suspect, dressed in black and armed with a rifle, was himself shot dead minutes later in a gunfight with police who converged on the scene of a confrontation that Mayor Kip Holden said began as an ''ambush-style'' attack on officers.
Two Baton Rouge Police Department officers and one sheriff's deputy were killed, while another sheriff's deputy was critically wounded. Another police officer and one other deputy suffered less severe wounds and were expected to survive.
Colonel Mike Edmonson, superintendent of the Louisiana State Police, told a news conference the gunman was believed to have acted alone, contrary to early reports that police may have been looking for other shooters.
Sunday's bloodshed followed days of unrest over the police killings of two black men under questionable circumstances earlier this month - Alton Sterling, 37, in Baton Rouge on 5 July, and Philando Castile, 32, near St Paul, Minnesota, on 6 July.
Police did not name the suspect. But a US government official told Reuters the gunman was identified as Gavin Long, of Kansas City, Missouri. Long, who was black, was a decorated ex-US Marine sergeant and was reported by other media to be 29 years old.
According to Long's military record, released by the Pentagon, he served in the Marines from August 2005 until August 2010, achieving the rank of sergeant. Listed as a data network specialist, he was deployed to Iraq from June 2008 until January 2009, earning several medals and commendations.
Authorities declined to offer a possible motive for Sunday's attack in Louisiana's capital, a city with a long history of distrust between African-Americans and law enforcement that was further inflamed by Sterling's slaying.
Social media postings linked to an individual named Gavin Long included a YouTube video posted 10 July saying he was fed up with mistreatment of blacks and suggesting that only violence and financial pressure would bring about change. He also said he was speaking from Dallas, where he had gone to join protests.
''It's only fighting back or money. That's all they care about,'' he said to the camera. ''Revenue and blood, revenue and blood, revenue and blood.''
In a separate video, he insists that should ''anything happen'' to him, he wanted his viewers to know he was ''not affiliated'' with any particular movement or group.
A second government source, speaking on condition of anonymity, said investigators had reason to believe an emergency 911 call may have been used to lure Baton Rouge police into harm's way.
In the ensuing pandemonium caught on a recording of emergency radio traffic, police are repeatedly heard reporting: ''Officer down'' and ''deputy down'' as officers swarmed the area searching for, and ultimately confronting, the gunman.
The episode was over in about eight minutes, according to Edmonson's account.
The three slain officers were identified by their superiors as Brad Garafola, of the East Baton Rouge Parish Sheriff's office, Matthew Gerald, and Montrell Jackson, who was black.
President Barack Obama condemned the attack and urged Americans to focus on rhetoric and actions that united the country, rather than divided it.
''We need to temper our words and open our hearts, all of us,'' Obama said in televised remarks from the White House.
Louisiana Governor John Bel Edwards called the shootings an ''unspeakable, heinous attack'' that served no purpose.