At least two snipers opened fire on police officers during protests in Dallas on Thursday night, killing four officers and injuring seven others, police said.
Dallas police chief David Brown told reporters the snipers fired "ambush style" upon the officers.
Police said a suspect in the killings who was in a shoot-out with Dallas SWAT officers was in custody, while a second "person of interest" had surrendered. They said a suspicious package was being secured by a bomb squad.
Brown had earlier said the police had a suspect cornered and were negotiating with him.
The gunfire broke out around 8.45pm local time on Thursday while hundreds of people were gathered to protest against fatal police shootings this week in Baton Rouge, Louisiana, and suburban St Paul in Minnesota.
The protesters had gathered after a Minnesota officer on Wednesday fatally shot Philando Castile while he was in a car with a woman and a child in St Paul.
The aftermath of the shooting was purportedly livestreamed in a widely shared Facebook video.
A day earlier, Alton Sterling was shot in Louisiana after being pinned to the pavement by two white officers. That, too, was captured on a mobile phone video.
Video footage from the scene in Dallas showed that protesters were marching along a street about half a mile from City Hall when the shots erupted and the crowd scattered, seeking cover.
Texas Governor Greg Abbott said he has directed the Texas Department of Public Safety director to offer "whatever assistance the City of Dallas needs at this time".
Abbott said: "In times like this we must remember -- and emphasise -- the importance of uniting as Americans."
The search for the gunman had stretched throughout central Dallas, an area of hotels, restaurants, businesses and some residential apartments.
The scene was chaotic, with helicopters hovering overhead and officers with automatic rifles on the street corners.
"Everyone just started running," Devante Odom, 21, told The Dallas Morning News. "We lost touch with two of our friends just trying to get out of there."
Carlos Harris, who lives in the area, told the newspaper that the shooters "were strategic. It was tap tap pause. Tap tap pause."
The gunshots in Dallas came amid protests nationwide over the recent police shootings.
In Manhattan, protesters first gathered in Union Square Park where they chanted "The people united, never be divided!" and "What do we want? Justice. When do we want it? Now!"
A group of protesters then left the park and began marching up Fifth Avenue blocking traffic during the height of rush hour as police scrambled to keep up.
Another group headed through Herald Square and Times Square where several arrests were reported.