President Barack Obama has urged Americans not to see the country as being driven into opposing groups, seeking to soothe raw emotions after an attack that killed five policemen in Dallas and the high-profile police shootings of two black men in Minnesota and Louisiana.
"First of all, as painful as this week has been, I firmly believe that America is not as divided as some have suggested," Mr Obama said.
"Americans of all races and all backgrounds are rightly outraged by the inexcusable attacks on police, whether it's in Dallas or any place else," he said, speaking at a news conference during a trip to Poland.
"That includes protesters. It includes family members who have grave concerns about police conduct, and they have said that this is unacceptable."
Authorities have named former US Army reservist Micah Johnson as the lone gunman in the attack in Dallas, which came at the end of a rally to protest against police killings. They said he had embraced militant black nationalism and expressed anger over police shootings and a desire to "kill white people, especially white officers."
"The demented individual who carried out those attacks in Dallas, he's no more representative of African-Americans than the shooter in Charleston was representative of white Americans or the shooter in Orlando or San Bernardino were representative of Muslim-Americans," Mr Obama said, referring to a string of mass shootings in the past year.
The attack in Dallas also wounded seven other officers and two civilians. Johnson, 25, was killed by a bomb-carrying robot deployed against him in a parking garage where he had holed up and refused to surrender during hours of negotiations with police, authorities said on Friday (local time).
President Obama, while saying there was a "persistent problem of African-Americans and Latinos being treated differently in our criminal justice system", stressed he did not believe the country was descending into the polarisation seen in the sometimes violent civil rights struggles of the 1960s.
He cited almost uniformly peaceful protests against police killings, and police handling the protests with professionalism.
The rally in Dallas followed the fatal police shootings of Philando Castile, 32, near St Paul, Minnesota, and Alton Sterling, 37, in Baton Rouge, Louisiana.
Referring to the death of Mr Castile, after a traffic stop, Mr Obama said "we don't know yet what happened, but we do know that there was a gun in the car that apparently was licensed but it caused, in some fashion, those tragic events."