Police killed the suspect with an explosive device after a standoff that lasted for hours, Chief David Brown said.
"We saw no other option but to use our bomb robot and place a device on its extension for it to detonate where the suspect was," Brown said. "Other options would have exposed our officers to grave danger. The suspect is deceased as a result of detonating the bomb."
The dead gunman was Micah X. Johnson, a 25-year-old resident of Dallas, law enforcement sources familiar with the investigaton told CNN.
Johnson apparently did not have a criminal history or any ties to terror groups, a law enforcement official said.
Five police officers were killed and seven others were injured in the ambush, which began during a protest over police violence Thursday night, officials have said. It was the deadliest single incident for U.S. law enforcement since September 11, 2001. Two civilians also were injured in the shootings, the Dallas mayor's office said.
The deadly gunfire erupted in Dallas as videos showing two African-American men shot by police in Louisiana and Minnesota spurred protests and debate over police use of force across the country.
Brown told reporters it's too soon to speculate on the suspect's motives, and it's unclear whether more suspects are on the loose.
"We're hurting. Our profession is hurting. There are no words to describe the atrocity that happened in our city," he said. "All I know is that this must stop -- this divisiveness between our police and our citizens."
Witnesses said protesters were marching peacefully in downtown Dallas when the gunfire started Thursday night. Crowds scattered.
"In the midst of it, gunshots just started barreling out," witness Michael Jackson told CNN's Don Lemon. "I immediately started running the opposite way."
G.J. McCarthy said he thought it was fireworks at first. Then the bangs got louder, he said, and protesters realized it was gunfire. Crowds ran into a parking garage, and spilled out after word spread a sniper was nearby.
"Everyone was screaming, people were running," said Clarissa Myles, who was eating at a McDonald's when the chaos erupted. "I saw at least probably 30 shots go off."
Police have said at least two snipers fired "ambush-style" from an "elevated position." Then police exchanged gunfire and negotiated with a suspect for hours at a parking garage in downtown Dallas.
Before authorities killed him with an explosive, the suspect told negotiators more officers were going to get hurt, and that bombs had been planted all over downtown.
Police found no explosives during primary and secondary sweeps of the area, Dallas police Maj. Max Geron said Friday morning on Twitter.
President Barack Obama, who is in Warsaw, Poland, said his team is keeping him updated. "We still don't know all the facts, we do know there's been a vicious, calculated and despicable act on law enforcement," Obama said. "I believe I speak for every American when I say we are horrified."
Police have said at least 10 officers were shot by a sniper, and that one officer was shot in a shootout at the parking garage. It's not clear where the 12th officer was shot.
Most of the injured officers have been released from the hospital, Brown told reporters. Their conditions are improving, Brown said, calling for the community to support them.
"We don't feel much support most days. Let's not make today most days," Brown said. "Please, we need your support to be able to protect you from men like these, who carried out this tragic, tragic event."
Officers killed include one officer with DART, the Dallas Area Rapid Transit agency, which operates buses and commuter rail in the city and surrounding suburbs.
DART identified that officer as Brent Thompson, 43. He joined the transit agency in 2009, and was its first officer killed in the line of duty, DART tweeted.
Thompson got married two weeks ago to a fellow transit officer, DART police Chief James Spiller told CNN's "New Day" on Friday.
Brown said an investigation into the ambush continues. He would not say how authorities believe others in custody are connected to the shooting.
Previously, authorities had said three people were in custody, and that multiple shooters were involved in the attack.
"I'm not going to be satisfied until we've turned over every stone. We've got some level that this one suspect did do some of the shooting. But we're not satisfied that we've exhausted every lead," he said. "So if there's someone out there who's associated with this, we will find you, we will prosecute you, and we will bring you to justice."
Asked about the gunman's motive, Brown declined to speculate.
"We can't get into the head of a person that would do something like this. We negotiated with this person that seemed lucid during the negotiation. He wanted to kill officers, and he expressed killing white people, he expressed killing white officers, he expressed anger for Black Lives Matter. None of that makes sense," Brown said. "None of that is a reason, a legitimate reason, to do harm to anyone. So the rest of it would just be speculating on what his motivations were. We just know what he said."
Retired FBI Special Agent Steve Moore said an attack of that magnitude required advance work.
"This was an attack planned long before -- waiting for an opportunity to go," Moore said. "I think there was so much logistically, ammunition-wise. They may not have planned the location, they may not have planned the vantage point. But they had prepared for an attack before last night's shooting is my guess."
The shootings occurred as many Americans nationwide took to the streets to demand answers over the killings of two black men in two days. They wept, marched and chanted, "Black Lives Matter!"
In St. Paul, Minnesota, crowds gathered near the spot where an officer killed Philando Castile in a car on Wednesday.
"We are targets," LaRhonda Talley said in an impassioned speech in Minnesota. "We made it across the transatlantic. We made it to freedom and you're still killing us. You're still hanging us from trees. You're still killing us. Our lives matter! My son's life matters. He matters to me ... just like everybody's son matters to their mama."
Hundreds of miles away, protesters marched outside a convenience store in Baton Rouge, Louisiana, where Alton Sterling was fatally shot Tuesday while police tackled him in a parking lot.
Both killings were captured on video and posted online.
In Minnesota, the shooting of Castile was remarkable -- and heartbreaking -- because his fiancée streamed the immediate aftermath live on Facebook.
As her 4-year-old sat in the back seat, Diamond Reynolds calmly narrated what was going on and showed viewers the dying man groaning and bleeding in the front seat.
Castile, a school food services worker, was shot in Falcon Heights, outside Minneapolis, when a police officer pulled him over because of a broken taillight, said Reynolds, who was in the car with him.
"He let the officer know that he had a firearm and he was reaching for his wallet and the officer just shot him in his arm," she said as she broadcast the Wednesday shooting on Facebook.
"Oh God, please don't tell me my boyfriend is dead," she said.
Baton Rouge shooting
Sterling, 37, was killed Tuesday near a convenience store in Baton Rouge, where he regularly sold CDs and DVDs.
A homeless man approached Sterling on Tuesday and asked for money, becoming so persistent that Sterling showed him his gun, a source told CNN.
The homeless man called 911, and police arrived at the store. Police tackled Sterling to the ground, and shot him several times, video shows.
A law enforcement source told CNN that the officers pulled a gun from Sterling's body at the scene. No further details were provided on the type of firearm.
The convenience store quickly became the site of protests. Flowers and signs piled up in a makeshift memorial. Protesters chanted "Hands up, don't shoot," the line made famous in the Michael Brown shooting in Ferguson, Missouri, about two years ago. Brown was also shot by a police officer.
Most major cities, including Chicago and New York, held protests against police shootings Thursday night.