(Updated 4:12 p.m. with comments from attorneys.)

The three agencies that made up the "unified command" during protests in Ferguson over the summer will have to provide warning before using tear gas or other chemical agents to disperse peaceful crowds.

The requirement settles a lawsuit Ferguson protesters brought against the St. Louis County police, St. Louis Metropolitan Police Department, and the Missouri State Highway Patrol. The agencies were sued for their use of tear gas and pepper spray during the protests that followed both the shooting death of Michael Brown in August, and the November announcement that former Ferguson police officer Darren Wilson would not face criminal charges in Brown's death. The plaintiffs alleged that officers acting under the orders of the unified command violated their right to free speech and assembly by indiscriminately using chemical agents against peaceful protesters who were often given no way to escape.

"It was an extreme situation, but frankly it's something that we may see again in the future if there are continued protests," said Thomas Harvey, the executive director of the Arch City Defenders and one of three attorneys who represented the protesters.

The lawsuit cites several incidents in which police used tear gas, Mace or pepper spray indiscriminately, but the one that garnered the most attention was an incident the night of the grand jury decision at MoKaBe's, a coffee shop in Tower Grove South that had become a headquarters for protesters. The lawsuit alleges that without warning, police fired several tear gas canisters at the cafe, which filled with tear gas. Protesters who tried to leave through the back were caught in an alley that was also filled with gas. St. Louis police chief Sam Dotson denied all the charges, and said the gas was being used against individuals attempting to destroy property along South Grand Avenue.

The language of the settlement basically mirrors a temporary restraining order issued by Judge Carol Jackson in December. Police will have to warn protesters that they will be using tear gas or other chemical agents and give members of the crowd a chance and a clear path to leave. The warnings would not be required if situations "turn violent and persons at the scene present an imminent threat of bodily harm to persons or damage to property, and when law enforcement officials must defend themselves or other persons or property against such imminent threat."

According to the Advancement Project, which helped represent the defendants, Thursday's settlement puts the three agencies in rare company. The nonprofit advocacy group says it believes only the Oakland, Calif. police department has similar policies limiting the use of chemical agents.

Harvey, the defendants' attorney, said it was unfortunate that it took a lawsuit for those limits to be put in place.

"If it wasn't for the folks in the streets taking this seriously, we never would have had this moment to really create some additional space for the people of America to express their First Amendment rights," he said.

Joseph Leahy | St. Louis Public Radio

The settlement requires the three departments to inform their officers of the new policy no later than Aug. 15. Each department must contribute $2,500 toward attorney fees. The federal court will monitor the case until January 2018.

Michael Hughes, an associate St. Louis County counselor, called the settlement "reasonable," a statement echoed by the city's attorney, Winston Calvert.

"The settlement agreement approved by the court today documents a commonsense agreement that will allow the St. Louis Metropolitan Police Department to continue to protect protesters' constitutional rights, keep people safe, and protect people's homes and businesses," Calvert said in a statement.

The Missouri attorney general, who represented the Highway Patrol, did not respond to a request for comment.

Follow Rachel Lippmann on Twitter:@rlippmann