A group of snipers attacked the police at a protest rally in Dallas.

12 police officers and two civilians were shot.

At least five officers were killed.

At least three people were taken into custody.

One person involved in a shootout with the police died after a police robot with a bomb was sent in and detonated.

Police officers outside the emergency room at Baylor University Medical Center on Friday in Dallas. (AP Photo/Tony Gutierrez) At least a dozen police officers were shot and at least five were killed in an attack near a protest and rally in downtown Dallas on Thursday night.

Mayor Mike Rawlings of Dallas said Friday morning that at least 12 officers and two civilians were shot. Four of the officers who died were from the Dallas Police Department; the other was from the Dallas Area Rapid Transit agency.

Two officers underwent surgery, and three are in critical condition, according to the police.

Dallas Police Chief David O. Brown said two snipers staged the attack from "elevated positions" near the protests and that the department thought the attackers coordinated the ambush.

By Friday morning, the police had killed one suspect using a robot-controlled bomb after negotiations in a standoff in a Dallas parking garage. Brown said the suspect said he was "upset about Black Lives Matter" and that he "wanted to kill white people."

"We cornered one suspect and we tried to negotiate for several hours," Brown said in a press conference on Friday.

"Negotiations broke down and we had an exchange of gunfire with the suspect," he said. "We saw no other option but to use our bomb robot and place a device on it for it to detonate where the suspect was. Other options would have exposed our officers to grave danger. The suspect is deceased, as a result of the detonating of the bomb."

Brown added: "The suspect said he was upset about Black Lives Matter. He said he was upset about the recent police shootings. The suspect said he was upset at white people. The suspect stated he wanted to kill white people, especially white officers." Brown also corrected earlier reports that said the suspect had killed himself.

The suspect was identified later Friday morning as 25-year-old Dallas resident Micah Johnson. He was not on any FBI watch lists, according to CBS News.

Brown said previously that the suspect had said "the end is coming" as he exchanged gunfire with the police and also said he would "hurt and kill" more police officers. Brown said the man also claimed to have placed bombs inside the El Centro College garage where the shootout took place. No bombs have been found, however.

Military experts have said the attackers appeared "tactically professional" and "focused." Three more suspects were taken into custody by the police, though Brown said in an earlier statement that the suspects in custody were not being very cooperative.

The standoff at the garage ended shortly before 3 a.m. CT on Friday.

The incident was part of the deadliest day for police officers since September 11, 2001, according to the National Law Enforcement Officers Memorial Fund.

Many streets in Dallas were still blocked off early Friday morning, and some flights into the city were canceled. Police operations are ongoing.

Dallas police officers stand in a line near the site of shootings in downtown Dallas, early Friday, July 8, 2016. (AP Photo/LM Otero)

At the Friday-morning press conference, Rawlings commented on the criticism of police militarization that in part inspired the protests in Dallas and across the US on Thursday night.

"If we're all being critical of those things, just think about today," he said. "This is what you're risking if you don't do it right. And so, from a policy standpoint, we believe in the right to protest peacefully, and these were peaceful protests until this happened. But we also have to believe in keeping these police officers safe. And I know I'm going to redouble my efforts on that."

Brown concurred.

"Police officers are guardians of this democracy," he said, adding: "So we risk our lives for those rights. So we won't militarize our policing standards, but we will do it in a much safer way every time."

He applauded his fellow officers for putting themselves in the line of fire to protect people.

"Please join me in applauding these brave men and women who do this job under great scrutiny, under great vulnerability," Brown said.

He added: "We don't feel much support most days. Let's not make today most days."

President Barack Obama addressed the shooting in a press conference from Warsaw, Poland, where he was meeting with NATO leaders, calling it a "vicious, calculated and despicable attack." He added that there was no possible justification for the attack and that justice would be done.

He also reiterated that the police had an "extraordinary difficult job and the vast majority do their job in outstanding fashion.

"Today is a wrenching reminder of the sacrifices they make for us," Obama said.

Dallas police moving to detain a driver after several police officers were shot in downtown Dallas on Thursday. AP Photo/LM Otero

Several people in custody

Negotiations with the man who engaged in the shootout at the El Centro garage went on for at least 45 minutes, though Brown said the man was "not very cooperative."

Brown said a woman was taken into custody along with two men who were carrying a camouflage bag.

Earlier Thursday night, the Dallas Police Department tweeted an image of a man wearing a camouflage-style shirt and carrying what appeared to be a rifle, indicating that the man was a person of interest. A follow-up statement from the police department said the man "turned himself in."

Several reports on social media later indicated that the man was not involved in the shooting. ABC News reported that a lawyer for the man confirmed that he was not a suspect and had been released by the police.

One man told CNN he recorded video that appeared to show a person shooting from a parking structure near the scene. Ismael Dejesus told anchor Don Lemon that he captured the video from his hotel room.

Watch that video here:

Witness Ismael Dejesus joins @donlemon to share the video he captured of the #Dallas shooting https://t.co/oBmEIv09rk — CNN (@CNN) July 8, 2016

Bystanders captured chilling video of that sniper using a set of pillars at the base of a large building as cover, as he shot at the police. In that video the gunman could be seen hunting down an officer who was attempting to subdue him.

In another video that emerged on social media soon after first reports of the incident, Dallas police officers could be seen shielding themselves behind vehicles at a street corner after shots were apparently fired during the protest.

"I heard about 20 shots in rapid succession," one witness told KTVT. A man seen on Facebook video said "there's an officer down ... I think another officer's down around the corner."

Here's more video from the scene:

#BREAKING: Our cameras captured several shots ring out during a protest in Downtown Dallas pic.twitter.com/OWOBOOI8Jg — FOX 4 NEWS (@FOX4) July 8, 2016

Here, a witness tells NBC5 of the shootings.

Several officers dead

Brent Thompson, of Dallas Area Rapid Transit, one of five officers killed in a shooting incident in Dallas, Texas, U.S., is pictured in this undated handout photo obtained by Reuters July 8, 2016. Handout via Reuters from the DART transit agency said that four of the agency's officers were injured, with one dead. The officer who was killed was identified as 43-year-old Brent Thompson, who joined the department in 2009.

The three other DART officers are expected to survive; they were identified as Omar Cannon, Misty McBride, and Jesus Retana.

One of the Dallas police officers who was killed has now been identified as Patrick Zamarripa.

Rallies have taken place across the US this week after police shootings in Baton Rouge, Louisiana, and Falcon Heights, Minnesota. Both of those shootings — in which black men were killed during encounters with law enforcement — have prompted rebukes from civil-rights leaders and elected officials across the country.

The violence that erupted in Dallas occurred as the peaceful rally was taking place.

Bryan Logan, Barbara Tasch, Natasha Bertrand, and Pamela Engel contributed reporting and writing.

This is a developing story and will be updated with new information as it comes in.