A man planted pipe bombs outside Dallas Police headquarters and sprayed the building with bullets during a wild street battle before being shot and killed in his van by a police sniper.
Dallas Police chief David Brown said the suspect identified himself to authorities as James Boulware, and he blamed police for having lost custody of his son and for "accusing him of being a terrorist". Officials declined to officially identify the suspect until a coroner verified it.
According to police, the suspect opened fire on the building from his parked van. Bullets pierced the glass at the entrance and caused damage inside, including at the front desk, where the worker on duty had just gone to get a soft drink.
He also fired on officers who drove up to confront him, riddling at least one squad car with bullets but not actually hitting anyone.
Mobile phone video shot from a nearby balcony or roof showed the suspect's dark van ram a squad car as gunshots rang out. At one point the suspect got out of his van and walked towards the entrance to the building firing his gun, but turned around, according to Major Jeff Cotner.
The van then fled, eventually stopping in a restaurant car park in the suburb of Hutchins, where the stand-off ensued.
The suspect had told police negotiators that he had explosives in the van, and Mr Brown said at a news conference that the department decided to shoot him because it felt he still posed enough of a threat.
"When the negotiation was on, he became increasingly angry and threatening, such that we were not only concerned with our officers there trying to contain the scene being shot by him at a moment's notice," but also people nearby, Mr Brown said.
Investigators found a package of pipe bombs in the car park at police headquarters and at least two more bombs in the van, police said.
Wary that the van might have been rigged with explosives, police used a camera-equipped robot to inspect it rather than have officers approach it immediately, which was why it took several hours to confirm he was dead.
After the suspect was confirmed dead, the van erupted in flames when authorities detonated the suspected ordnance inside.
Boulware's father said his son had strong feelings against law enforcement after he lost custody of his son, now 12 or 13 years old.
Boulware spent several hours on Friday at his father's home in Carrolton, a Dallas suburb, and talked about how well his recently purchased van drove, the father said.
But he also discussed a widely publicised video of a police officer in McKinney, Texas, pushing a black teenager to the ground and brandishing his gun at other teenagers.
His father last spoke with Boulware by telephone about three hours before Dallas Police said the shooting began.
"Not being able to get a job and the legal system letting him down, (he) finally snapped," the elder James Boulware said in a telephone interview before police arrived. "But I can't say shooting at a police station is right in any way."
The attack began at around 12.30am when several officers were standing nearby. A popular bar across the street from the headquarters was still open, and the neighbourhood is also home to a boutique hotel and apartment buildings.