MEXICO CITY — An army officer and seven soldiers have been detained by the Mexican Defense Department in connection with the killing of 22 people in what is being investigated as a possible massacre in western Mexico in June.

The arrests, on charges of crimes against military discipline, disobedience and dereliction of duty, announced in a statement late Thursday, represent a reversal for the military and some senior Mexican officials. The officials initially described the encounter on June 30 in San Pedro Limón as a shootout between soldiers and local gang members, with the soldiers firing in self-defense.

“The official story is falling apart,” said José Miguel Vivanco, director of Human Rights Watch’s Americas division.

President Enrique Peña Nieto told reporters this week in New York, where he attended the United Nations General Assembly, that the attorney general’s office was delving into the case. His term so far has been defined in part by efforts to focus attention on the economy, and away from crime and Mexico’s dysfunctional justice system, but an agency spokesman said Friday that civil and military prosecutors were conducting separate inquiries and sharing information.