NEW YORK — The New York Police Department has agreed not to conduct surveillance based on religion or ethnicity and to listen to Muslims as it develops new training materials as part of a deal to settle claims it illegally spied on Muslims for years after the Sept. 11 attacks.

The agreement announced Thursday by the city and the Islamic community also calls for the city to pay $75,000 in damages and nearly $1 million in legal fees. It also ensures surveillance in New Jersey will follow rules defined in another landmark civil rights case.

"Today's settlement sends a message to all law enforcement: Simply being Muslim is not a basis for surveillance," said Farhana Khera, executive director of Muslim Advocates, a legal advocacy and educational organization.

"We won this case, make no mistake about it. But as a member of the armed forces, I believe the United States won as well," said Farhaj Hassan, a U.S. Army reservist and the lead plaintiff in the 2012 lawsuit in federal court in Newark, New Jersey.

"No one likes to take on the cops. Cops are good," he said. "But in this case, when cops were acting bad, it had to be done."

The lawsuit came after The Associated Press revealed in a series of Pulitzer Prize-winning articles how the NYPD infiltrated Muslim student groups and put informants in mosques as part of a broad effort to prevent terrorist attacks. In New Jersey, the department collected intelligence on ordinary people at mosques, restaurants and schools starting in 2002, the AP reported.

At a news conference, the plaintiffs noted that surveillance program never produced a terrorism lead as it spied on at least 20 mosques, 14 restaurants, 11 retail stores, two grade schools and two Muslim student associations in New Jersey.

The deal came after a Philadelphia appeals court in 2015 likened the surveillance program to when Japanese Americans were interned during World War II and discrimination before racial unrest in the 1950s and 1960s forced change.

Baher Azmy, legal director of the Center for Constitutional Rights, said the agreement protects an increasingly empowered Muslim community.

It bans the police department from conducting surveillance without suspicion on the basis of religion or ethnicity and calls for the Muslim litigants to provide input into a new policy guide to control the police department's Intelligence Bureau. It also requires NYPD counter-terrorism probes in New Jersey to follow the Handschu Guidelines, which resulted from a 1971 lawsuit by the Black Panther Party alleging police engaged in widespread surveillance of legitimate political activity.

It also requires the city to pay $47,500 to businesses and mosques harmed by surveillance and $25,000 to individual plaintiffs in $5,000 increments. The city also will pay $950,000 in legal fees for plaintiffs.

"This settlement demonstrates a continued commitment by the NYPD to safeguard individual constitutional rights while keeping New York the safest city in America," said Zachary W. Carter, the city's top lawyer.