SUTHERLAND SPRINGS, Tex. — The gunman behind the worst mass shooting in Texas history escaped from a psychiatric hospital while he was in the Air Force, and was caught a few miles away by the local police, who were told that he had made death threats against his superiors and tried to smuggle weapons onto his base, a 2012 police report showed.

That episode, which came to light on Tuesday, was another in a series of red flags about the threat the gunman, Devin P. Kelley, posed to those around him. But none of the warnings stopped Mr. Kelley from legally purchasing several firearms, including the rifle he used to kill 26 people at the First Baptist Church of Sutherland Springs on Sunday.

According to an El Paso Police Department report from June 2012, officers took Mr. Kelley, then 21, into custody at a bus station in downtown El Paso, where he apparently planned to flee on a bus after escaping from Peak Behavioral Health Services, a hospital a few miles away in Santa Teresa, N.M. He had gone to Peak Behavioral, whose services include a program for military personnel, after being charged in a military court with assaulting his wife and baby stepson, charges he later pleaded guilty to.

The report filed by the El Paso officers says that the person who reported Mr. Kelley missing from the hospital advised them that he “suffered from mental disorders,” and that he “was attempting to carry out death threats” against “his military chain of command.” The man “was a danger to himself and others as he had already been caught sneaking firearms onto Holloman Air Force Base,” it added.