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, named as Micah Johnson, 25, said he was upset about the recent police shootings of black people, Police Chief David Brown said.
Five police officers were killed and seven wounded during a march against the shooting of black men by police.
Three people are in custody but it is not clear if there were other gunmen.
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 had taken cover. 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 had acted alone.
However, speaking earlier on Friday, Mr Brown had said two snipers had fired from "elevated positions", shooting some officers in the back.
At the scene - Tara McKelvey, BBC News, Dallas
Red roses and worn-looking stuffed toys are left on Griffin Street near the place where the officers were shot.
Dozens of police are now patrolling the area under a harsh afternoon sun, and workers from a nearby Westin hotel are lugging around bottled water and granola bars to give to the officers.
Things are tense. Brandt Sadlowski, 24, got into an argument with the officers over his handgun, a 9mm that he carries on his belt.
That's legal in Texas, but the officers asked him to steer clear of the memorial site. The police don't want any more incidents - especially not today.
The White House later said investigators had ruled out any connection to a terrorist organisation.
Micah Johnson lived with his mother in Mesquite, an eastern suburb of Dallas, and had been a member of the US Army Reserve, US media reported.
Investigators later sealed off and searched his home, carrying away several bags of material.
Gunfire broke out at around 20:45 local time on Thursday (01:45 GMT Friday) as demonstrators marched through the city. There was panic as people scrambled for cover. Police described the ambush as carefully planned and executed.
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 were also injured in the shootings. One underwent surgery for a gunshot wound in the leg.
He said the three suspects in custody so far were not co-operating and were "tight-lipped".
President Barack Obama, who is attending a Nato summit in Poland, called it a "vicious, calculated and despicable attack on law enforcement".
He later ordered all flags on public buildings to be flown at half-mast.
US Attorney General Loretta Lynch described events in Dallas as "an unfathomable tragedy".
"Americans across our country are feeling a sense of helplessness, of uncertainty and of fear," she said.
"These feelings are understandable and they are justified. But the answer must not be violence."
The Dallas attack marks the deadliest day for US law enforcement officers since the 9/11 attacks in 2001.
The protest march that wound its way through the city was 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.
Shock in Minnesota: Barbara Plett Usher, BBC News, St Paul
The disturbing video of Philando Castile's dying moments galvanised Pastor Thomas Mite to speak out more publicly against police killings.
But, he said, the Dallas attacks have been a setback to the activists' push for change and justice. The mood in St Paul was sober as residents absorbed this shock turn of events and what it might mean.
"Dallas is 'bigger than Philando," Mr Castile's girlfriend said to media at the protest site outside the governor's mansion, adding: "This is bigger than all of us."
"I hope there is justice for the people who did the killing in Dallas and for the person who did the killing here," said one of the protesters. Then he returned to abiding fears.
"I hope no cop gets angry here and tries to take revenge."
"The police will protect themselves,' Pastor Mite mused. "They have a right to go home safely at night, but they'll come out with riot gear and shields. This is bad."