District police acknowledged that they sent an undercover officer to infiltrate a group of student demonstrators this year but contended that it was because a uniformed officer had been assaulted during a protest, not to monitor speech.

The explanation was filed last week in D.C. Superior Court to answer a lawsuit against the police department by United Students Against Sweatshops. The group contends that police violated its First Amendment rights by spying on its members.

The D.C. attorney general’s office, which represents the police department in civil litigation, said in the court filing that an officer was assaulted May 1 outside a Gap store on Connecticut Avenue. Officials had a “corresponding concern of further violence” and requested “the use of undercover officers to monitor further demonstrations,” the court papers said. That request was approved by a senior commander.

The filing represents the first time District officials have acknowledged using an undercover officer, Nicole Rizzi, who was exposed by the protest group’s leaders after they matched pictures of her taken at demonstrations to photos she used on personal ­social-media sites.

Attorneys for the District argued that police used “the least intrusive means to conduct the investigation” and that they had “reasonable suspicion that criminal activity had occurred” — two requirements under a law enacted to restrict police monitoring of protests.

The District argued that the protesters have not been harmed by the undercover work and that members “were not chilled in their speech as they did not know an undercover officer was present.”

Ted Gest, a spokesman for the D.C. attorney general’s office, declined to comment further. A hearing is scheduled for Nov. 22.

Jeffrey Light, the attorney for the protest group, said police could have sent uniformed officers to future protests if they thought violence was likely. “It’s not a reason to have an undercover there,” he said. The group typically demonstrates at stores that sells products made in what members consider to be sweatshops.

Police charged a 36-year-old protester with assault on a police officer about a week after the May 1 protest. But court records show that a judge dismissed the case when prosecutors showed up at his trial without their key witness.

Light said the protester acted in self-defense after an officer punched him in the mouth.

Another protester at the May 1 demonstration, Sara Shaw, has sued the same officer who was involved in the altercation. She accuses the officer of using excessive force while taking her to the ground at the demonstration. She also is represented by Light.

The attorney general’s office denied Shaw’s allegations in court documents.