The gunman killed in a stand-off with Dallas police said he wanted to kill white people, especially officers, the city's police chief has said.
The suspect told police that he was upset about the recent police shootings of black people, Police Chief David Brown told reporters.
Five Dallas police officers were killed and seven wounded by snipers during a march 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. Before that he had spoken to a negotiator.
"He said he was upset about Black Lives Matter [protest movement]; he said he was upset about the recent police shootings," Mr Brown told a news conference.
"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 that the man had said he was not affiliated with any groups and he acted alone. However, police have said they believe that more than one gunman was involved.
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.
The protests came after this week's deaths of Philando Castile in Minnesota and Alton Sterling in Louisiana.
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.