The gunman killed in a stand-off with Dallas police said he was upset about the police shootings of black people and wanted to kill white officers, the city’s police chief has said.
The suspect told police that he was working alone, Police Chief David Brown told reporters.
Five Dallas police officers were killed and seven wounded by snipers during peaceful protests against the shooting of black men by police, officials say.
Three people are in custody.
Mr Brown said the suspect had been killed when police used explosives placed by a robot to end a tense stand-off in a building where he was holed up.
He said the gunman had told a negotiator that he was “upset about Black Lives Matter [protest movement], he said he was upset about the recent police shootings. The suspect said he was upset at white people. The suspect stated that he wanted to kill white people, especially white officers.”
Mr Brown added: “He said he was not affiliated with any groups, and he did this alone.”
Gunfire broke out at around 20:45 local time on Thursday (01:45 GMT Friday) as demonstrators marched through the city. Police described the ambush as carefully planned and executed.
President Barack Obama, who is attending a Nato summit in Poland, called it a “vicious, calculated and despicable attack on law enforcement”. He said the entire city of Dallas was grieving and the “tight-knit US police community feels this loss to their core”.
Speaking earlier, Mr Brown said the suspects were believed to have been working together, using rifles to carry out attacks while the protest rally was drawing to a close.
Two snipers had fired from “elevated positions”, shooting some officers in the back, he said.
“We believe that these suspects were positioning themselves in a way to triangulate on these officers from two different perches… and planned to injure and kill as many law enforcement officers as they could,” Mr Brown said.
The Dallas attack marks the deadliest day for US law enforcement officers since the 9/11 attacks in 2001.
Officers later surrounded a car park near El Centro College where the stand-off with the suspect took place.
Dallas Mayor Mike Rawlings said that two civilians, one man and one woman, were also injured in the shootings.
He told the NBC Today programme that the suspects in custody so far were not co-operating and were “tight-lipped”.
Mr Obama said that “anyone involved in these senseless murders will be held fully accountable”.
He said that “when people are armed with powerful weapons it makes attacks like these more deadly and more tragic”, a subject that, he said, must be addressed in “the days ahead”.
The Dallas protests were among several held across the US over the police use of lethal force against African Americans.
Philando Castile was shot dead after being stopped in his car by police in St Paul, Minnesota , on Wednesday.
Alton Sterling was killed by police a day earlier in Baton Rouge, Louisiana.
Both incidents were captured on video, reigniting what has become a national debate.