DALLAS — The gunman who killed five police officers and wounded nine other people in Dallas on Thursday was accused of “egregious” sexual harassment in the Army and spent years accumulating a stockpile of weapons, according to investigators and his military lawyer.

The new details about Micah Xavier Johnson, 25, emerged Saturday as Dallas mourned victims of the nation’s deadliest incident for law enforcement since the Sept. 11, 2001, terrorist attacks. Johnson was killed by a police robot bomb after he attacked officers at a demonstration in downtown Dallas protesting recent shootings of black men by police.

Investigators believe that Johnson assembled an arsenal of bombmaking materials, five handguns and an assault rifle over the past two or three years, according to a federal law enforcement official who spoke on the condition of anonymity.

Officials have said that Johnson, who was black, kept a journal filled with combat tactics and wanted to kill white police officers.

Investigators also are digging into Johnson’s military history and are seeking to corroborate reports that he was sent home from Afghanistan after a sexual harassment complaint was lodged against him in 2014, another federal law enforcement official said.

Bradford Glendening, the lawyer who represented him, told the Associated Press that the military recommended an “other than honorable discharge.”

“In his case, it was apparently so egregious, it was not just the act itself,” Glendening said. “I’m sure that this guy was the black sheep of his unit.”

According to a court filing Glendening read to the AP, the victim said she wanted Johnson to “receive mental help” and sought a protective order to keep him away from her and her family, wherever they went. Johnson was ordered to avoid all contact with her, Glendening said.

Johnson joined the Army Reserve in March 2009 and served in a unit in Seagoville, Texas, for 41/2 years. He deployed to Afghanistan in 2013 and served eight months as a carpentry and masonry specialist with the 420th Engineer Brigade.