Barack Obama has said the shooting of about a dozen police officers in Dallas was a vicious, calculated and despicable attack on law enforcement.
Mr Obama said America is horrified over the shootings and there was no possible justification for them, but added that all Americans should be troubled by frequent police shootings of blacks and Hispanics.
Mr Obama said justice will be done and asked all Americans to pray for the fallen officers and their families. He also said the nation should express its gratitude to those serving in law enforcement.
Snipers opened fire on police officers in the heart of Dallas on Thursday evening, killing five officers and injuring six others during protests over two recent fatal police shootings of black men in Baton Rouge, Louisiana, and St Paul, Minnesota.
Mr Obama said earlier there was no contradiction between supporting law enforcement and making sure biases in the justice system are rooted out.
Though the White House has sought to avoid commenting on specific cases before all facts are known, in this case Mr Obama weighed in while both shootings were still being investigated, including a civil rights probe by the Justice Department into the Louisiana incident.
The president called on American law enforcement to root out bias in its ranks and insisted that the fatal incidents in Minnesota and Louisiana are not isolated.
Mr Obama said the shootings were symptoms of a "broader set of racial disparities" in the justice system that are not being fixed quickly enough.
He listed statistics he said showed concerns about bias are real - with African-Americans being shot by police or arrested at more than twice the rate of white Americans.
"When incidents like this occur, there's a big chunk of our fellow citizenry that feels as if it's because of the colour of their skin, they are not being treated the same," Mr Obama said.
"And that hurts. And that should trouble all of us."
His diagnosis of the problem reflected a growing sense of frustration and willingness to speak out publicly about police killings despite the risk of making law enforcement officers feel under attack.
Aiming to pre-empt that concern, Mr Obama said that speaking out about the issue is not an attack on police.
He emphasised that he and other Americans appreciate the risks police take and mourn officers who die in the line of duty.
"When people say 'black lives matter', that doesn't mean blue lives don't matter," Mr Obama said, referring to uniformed officers. "That just means all lives matter."