Five Dallas police officers have been killed and six wounded by gunmen during protests against the shooting of black men by police, authorities say.
Three people are in custody and one man who was in a stand-off with police shot himself dead, US media have reported.
Gunfire broke out at around 20:45 local time on Thursday (01:45 GMT Friday) 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.
Eyewitness: "I didn't see anyone else being shot, it was just the cops"
Police are continuing to sweep the downtown area.
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 earlier: "We do not have a comfort level that we have all the suspects."
A transport police officer comforts a relative at Baylor University Hospital
The mayor of Dallas said this was a "heartbreaking moment for the city"
He said that 11 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.
One civilian, named by her family as Shetamia Taylor, was shot in the leg while protecting her children and is recovering in hospital.
Mr Obama said that "anyone involved in these senseless murders will be held fully accountable".
He said the attacks were a "wrenching reminder" of the sacrifices made by law enforcement officers.
The Officer Down Memorial website says 53 US officers have died in the line of duty in 2016, 21 of them as a result of gunfire. The toll does not include those killed in Dallas.
Mr Obama added 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".
Police had earlier issued a photo of one man at the rally with a rifle slung over his shoulder, saying he was a suspect.
The man, named as Mark Hughes, turned himself in to police and was later released.
The Dallas protests were among several held across the US over the police use of lethal force against African Americans.
The protesters have been angered by the deaths of black men at the hands of police
The protest was peaceful before the gunfire erupted
Philando Castile was shot dead at a traffic stop in St Paul, Minnesota , on Wednesday, while 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.
Pointing to statistics showing African-American citizens are far more likely to be shot by police than whites, Mr Obama has called on law enforcement to root out internal bias.