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 were sparked by the deaths of Philando Castile in Minnesota and Alton Sterling in Louisiana.
The Dallas attack marks the deadliest toll on US law enforcement officers since the 9/11 attacks in 200.
Dallas Police Chief David Brown said officers had surrounded a car park near El Centro College, where an armed man was firing off rounds with a rifle.
He 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”.
But 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.
Chief Brown said that a woman who was in the vicinity of the suspect was now 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 being questioned.
Chief Brown said the suspects were all believed to have been working together, using rifles to carry out attacks while the rally was taking place.
He added: “We do not have a comfort level that we have all the suspects.”
He had earlier said 11 officers were shot “ambush style” by sniper fire, killing three. Dallas police later tweeted that a fourth officer had died. The Dallas Police Association later confirmed a fifth had died.
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.
The police said it appeared that two snipers had fired from “elevated positions” during the protest rally.
“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.
The mayor of Dallas, Mike Rawlings, said it was a “heartbreaking moment for the city”.
Officers lined up to salute their fallen comrades as ambulances arrived at Parkland hospital.
One of the march’s organisers, Rev Jeff Hood, saw people scramble for cover as gunfire rang out.
“I ran away from the shots trying to get people off the streets and I was grabbing myself to see if I was shot,” he told the Dallas Morning News.
Police had earlier issued a photo of one man with a rifle slung over his shoulder, saying he was a suspect. Police later tweeted that he had handed himself in.
A man identifying himself as his brother told local TV that his brother was not involved and US media later reported that the man had been released from custody.
Flights over Dallas have been restricted.
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 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.
US President Barack Obama said “all fair-minded people should be concerned” about the frequent police killings of black Americans.
Pointing to statistics showing African-American citizens are far more likely to be shot by police than whites, Mr Obama called on law enforcement to root out internal bias.
“When incidents like this occur, there’s a big chunk of our fellow citizenry that feels as if it’s because of the colour of their skin, they are not being treated the same,” he said. “And that hurts.”
But Mr Obama also said there was “extraordinary appreciation and respect for the vast majority of police officers who put their lives on the line to protect us every single day. They’ve got a dangerous job. It’s a tough job.”
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.