Five police officers were killed and seven others wounded in a sniper-style attack by a black army veteran during a protest in Dallas against police brutality towards African-Americans.

Two civilians were also wounded on what was said to be the single deadliest day for law enforcement since September 11, 2011.

Police cornered the main shooting suspect, and tried to negotiate with him, but the talks broke down after several hours.

There was an exchange of gunfire with police, and the suspect finally died in a blast caused by a robot-controlled explosive device sent in by officers.

"He threatened other bombs, and we felt that was the safest way to get in and it was," Dallas Mayor Mike Rawlings said.

Who is behind the attack?

Police formally identified the slain suspect as 25-year-old Micah Johnson. The black man, a resident of the Dallas suburb of Mesquite, had no prior criminal record and was described to police as a "loner."

The US Army confirmed that Johnson served as a reservist for six years, including a tour of duty in Afghanistan.

Bomb-making materials, weapons and ammunition were found in his home, police said.

Police initially said it seemed two shooters were involved, but US Homeland Security Secretary Jeh Johnson said Friday the gunman appeared to have acted alone.

However, Texas Governor Greg Abbott said police would "continue down every rabbit trail... ensuring that we eliminate any other possible suspects or co-conspirators who may have aided this gunman in any way."

The lone gunman had posted a rant against white people on a black nationalist Facebook group called Black Panther Party Mississippi last Saturday, denouncing the lynching and brutalizing of black people.

"Why do so many whites (not all) enjoy killing and participating in the death of innocent beings," Johnson wrote in a post above a graphic video of a whale-killing, comparing it to the treatment of black people in the United States.

In what appeared to be his own Facebook page, Johnson was portrayed with the red, black and green flag sometimes known as the Black Liberation flag. His profile photo showed him with his clenched fist in the air in the familiar Black Power salute.

The U.S. Army said Johnson, 25, had served as a private first class in the Army Reserve and was deployed to Afghanistan from November 2013 to July 2014. It said Johnson served from March 2009 to April 2015 and was a carpentry and masonry specialist with the 420th Engineering Brigade based in Texas.

What was the motive?

Dallas police chief David Brown said that in negotiations with police during the ultimately fatal standoff, the gunman 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 said.

While the White House ruled out any link between the gunman and known "terrorist organizations," Johnson's Facebook page ties him to several radical black activist movements listed as hate groups by the Southern Poverty Law Center.

Groups that he "liked" include the New Black Panther Party (NBPP) and the Nation of Islam, both known for expressing virulently anti-Semitic and anti-white views, the SPLC said in a statement.