The gunman who killed three police officers in the United States city of Baton Rouge had posted video messages complaining about the treatment of African-Americans by police.
The gunman, Gavin Long, an African-American, was himself shot to death minutes later in a gunfight with police who converged on the scene.
He has been identified as a former US Marine who served for five years.
Long had posted videos on the internet complaining about police treatment of African-Americans.
Tensions in Baton Rouge have been high since Alton Sterling, a 37-year-old African-American father of five, was shot and killed at close quarters by police officers on 5 July.
That death - and a second police shooting in Minnesota - sparked protests across the United States and triggered a revenge attack by a black army veteran who shot dead five officers in the city of Dallas.
In one video, posted on YouTube, Long said that should "anything happen" to him, he was "not affiliated" with any group.
"I'm affiliated with the spirit of justice, nothing more, nothing less. I thought my own thoughts, I made my own decisions," he said.
In a live broadcast from the White House, President Barack Obama called upon all Americans to unite and refrain from divisive language.
"Regardless of motive, the death of these three brave officers underscores the danger that police across the country confront every single day, and we as a nation have to be loud and clear that nothing justifies violence against law enforcement," he said.
"Everyone right now focus on words and actions that can unite this country rather than divide it further," he added, as the US begins two weeks of political conventions with Republicans meeting in Cleveland later on Monday.
"We need to temper our words and open our hearts... all of us," said the president.
A vigil was attended by police officers and members of the public on Sunday evening at Saint John the Baptist Church in Zachary, just north of Baton Rouge.
Exchange of fire
The incident began on Sunday morning (local time) with shots being fired at a petrol station on Airline Highway in Baton Rouge.
Police received reports of a man with an assault rifle.
Witness Brady Vancel told WAFB TV he saw what may have been gang members shooting at each other before police arrived.
He told CBS he had seen a gunman, a second man in a red shirt lying in a parking lot and another gunman running away "as shots were being fired back and forth from several guns."
He said police arrived shortly after the gunfire began.
Another witness said she saw a gunman wearing a black mask and military-style clothing.
Shots were exchanged over a period of more than 15 minutes, leaving three police officers and the suspect dead, with three other officers wounded, one in a critical condition.
The dead officers were named as Montrell Jackson, 32, and Matthew Gerald, 41, of the Baton Rouge police department, and Sheriff's Deputy Brad Garafola, 45. All three men had families.
The suspect was named as 29-year-old Gavin Long, of Kansas City, Missouri, a former Marine.
He received an honourable discharge, and won several medals while in the military, including one for good conduct.
The city's mayor Kip Holden said the officers were responding to a call of shots fired when they were ambushed.
Authorities did not name the suspect, but a government official told Reuters the gunman had been identified as Gavin Long, of Kansas City, Missouri. He was reported by other media to have been 29 years of age and black.
According to the New York Times, Long served in the Marines for five years, from August 2005 to August 2010, and was deployed to Iraq from June 2008 to January 2009. CBS News reported that Long left the Marines with an honourable discharge in 2010 with the rank of sergeant.
Police believe the man shot dead was the only one involved in the attack, Mike Edmonson, superintendent of the Louisiana State Police, told media.
"We do not have an active shooter scenario in Baton Rouge," said Mr Edmonson.
Police had earlier told reporters authorities were seeking more than one person.
Earlier, a spokesman for the East Baton Rouge Sheriff's Office said police and sheriff's deputies were involved in the shooting incident, which occurred around 9am local time.
"Multiple officers from both agencies sustained injuries and were transported to local hospitals," he said in an email. He said there were no firm numbers on the number hurt or the extent of injuries.
While the scene of the shootings was contained, police warned residents to stay away from the area, near Airline Highway, which is a mile from the Baton Rouge Police Department headquarters, where dozens of protesters were arrested earlier this month.
It was not immediately clear whether there is a link between the Baton Rouge shootings and the recent unrest over police killings of black men in Baton Rouge and Minnesota.
The Black Lives Matter civil rights movement has called for police to end racial profiling, bringing the issue to national attention ahead of the 8 November US presidential election.
The Justice Department, which has opened a federal probe into Alton Sterling's death, declined to comment on the Baton Rouge shootings.
- Reuters / BBC