New York City's police department will install a civilian representative to help monitor its counterterrorism efforts as part of a settlement of two lawsuits claiming the department illegally targeted Muslims for surveillance, according to court papers filed on Thursday.

Details of the accord came months after court filings indicated the city had agreed in principle to settle separate federal lawsuits brought in Manhattan and Brooklyn by the New York Civil Liberties Union and other civil rights advocates.

Following the attacks of Sept. 11, 2001, the department pursued an aggressive surveillance program that sent undercover officers into Muslim neighborhoods, organizations and mosques.

The tactics, which became widely known after a series of reports by The Associated Press, were criticized by civil rights advocates as unconstitutional.

Mayor Bill de Blasio, who campaigned in part on reining in police excesses, ended the program soon after taking office in 2014.

"New York City's Muslim residents are strong partners in the fight against terrorism, and this settlement represents another important step toward building our relationship with the Muslim community," de Blasio said in a statement on Thursday.

RELATED: NYPD to start issuing stop-and-frisk receipts

The settlements require modifications to longstanding court-approved regulations, known as the Handschu guidelines, that limit how the department can monitor political activity. The guidelines were loosened after the Sept. 11 attacks.

The new changes, such as prohibiting police from using race or religion as a motivating factor in investigations, mostly formalize what is already departmental policy, according to police officials.

"Incorporating existing NYPD practices into the Handschu Guidelines makes it easier to maintain best practices in intelligence gathering and investigations," Police Commissioner William Bratton said.

The city is not admitting wrongdoing as part of the agreements, which must be approved by federal judges.

Still, the plaintiffs' supporters said the modifications provided crucial safeguards against unconstitutional profiling.

"At a time of rampant anti-Muslim hysteria and prejudice nationwide, this agreement with the country's largest police force sends a forceful message that bias-based policing is unlawful, harmful, and unnecessary," said Hina Shamsi, the director of the American Civil Liberties Union's national security project.

The deal calls for at least a five-year term for the civilian representative, who will have access to intelligence files and report any potential violations to either the commissioner or a federal judge.

The city will also pay about $2 million to cover the plaintiffs' legal costs.

A similar lawsuit brought in New Jersey against the NYPD remains pending after a U.S. appeals court in October reversed a judge's decision to dismiss the case. That lawsuit is unaffected by Thursday's settlements.