Dallas police shooting: Five officers killed, seven wounded by gunmen
Three people are in custody and one man who was in a stand-off with police shot himself dead, US media said.
Gunfire broke out at around 20:45 local time on Thursday (01:45 GMT Friday 08/07/2016) as demonstrators marched through the city.
The protests came after this week's deaths of Philando Castile in Minnesota and Alton Sterling in Louisiana.
The Dallas attack marks the deadliest day for US law enforcement officers since the 9/11 attacks in 2001.
President Barack Obama, who is visiting Poland, said it was 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".
Dallas Police Chief David Brown said the suspects were all 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.
"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," Chief Brown said.
Officers later surrounded a car park near El Centro College, as an armed man fired off rounds with a rifle.
Chief Brown said the suspect had told negotiators that "the end is coming" and that he was going to attack more officers and had "bombs all over the place".
US media say the man is now dead from a self-inflicted gunshot wound and the stand-off is over, although the police have yet to confirm this.
Police are continuing to sweep the downtown area. No explosives have been found so far.
A woman who was in the vicinity of the suspect at the car park is being questioned.
Police also said officers had intercepted a car after a person threw a camouflaged bag into the back and sped off. Two occupants were detained.
Chief Brown said that officers had been shot "ambush style" by sniper fire.
One of those killed was Brent Thompson, 43, a transport police officer with the Dallas Area Rapid Transit (DART). He is the first DART officer to be killed in the line of duty.
Amateur video footage showed one police officer approaching a gunman and taking cover behind a concrete pillar. The gunman shoots the officer at least twice, leaving him motionless, and then flees.
Dallas Mayor Mike Rawlings told the NBC Today programme that the suspects so far were not co-operating and were "tight-lipped".
"We're glad that we took down one of the suspects. We hope we have got everybody, but we can't be sure," he said.
He said that two civilians were also injured in the shootings, one man and one woman.
The woman, named by her family as Shetamia Taylor, was shot in the leg while protecting her children and is recovering in hospital.
Source: bbc.com