The alleged gunman who killed nine people and wounded nine others at a rural community college in Oregon last Thursday had been discharged from the Army after attempting to commit suicide, according to law-enforcement officials familiar with the case.

Christopher Harper-Mercer, who was 26 years old at the time of the shooting, was discharged from basic training at Fort Jackson, S.C., after just one month in 2008.

The...