President Obama has called for restraint after three police officers were shot dead in the city of Baton Rouge in Louisiana.
The gunman, an African-American who had served for five years in the Marines, was also killed.
Tensions in the city have been high since a black man Alton Sterling was shot dead by police two weeks ago.
It remains unclear whether Sunday's incident was related to that death and a second police killing in Minnesota.
Those two deaths spared 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 a live broadcast from the White House, President 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.