Facebook is taking steps to block discriminatory ads for housing, employment and credit by preventing advertisers from targeting users based on race, gender, age and zip code.

The American Civil Liberties Union (ACLU) and other rights groups, which sued Facebook for violating civil rights laws with its ad practices, announced the “historic settlement” on Tuesday, saying “sweeping changes” would restrict illegal and discriminatory ad targeting.

Facebook has for years faced criticisms over the ethics and legality of the way it lets advertisers “micro target” ads to specific groups of users. The company’s previous system had effectively allowed advertisers to exclude users based on race and other categories protected under anti-discrimination laws, meaning landlords, lenders, employers and others could restrict groups from seeing specific ads.

Facebook was specifically accused of allowing employers in male-dominated fields to target their ads only to men. The platform also previously faced intense backlash when reporters found the company allowed advertisers to target people based on offensive categories, such as “Jew hater” and “How to to burn Jews”.

Although Facebook repeatedly announced steps to stop illegal ad targeting, civil rights organizations and journalists have continued to uncover loopholes. Previously, advertisers could target racial groups by proxy, relying on the platform classifying users’ “ethnic affinity”.

“We are pleased Facebook has agreed to take meaningful steps to ensure that discriminatory advertising practices are not given new life in the digital era, and we expect other tech companies to follow Facebook’s lead,” Galen Sherwin, ACLU senior staff attorney, said in a statement.

In addition to banning discriminatory ads targeting for housing, employment and credit, Facebook said it would also block “any detailed targeting option describing or appearing to relate to protected classes”. The company has further agreed to build a separate advertising portal for housing, jobs and credit, so that users can search for and view all ads, regardless of whether they were targeted.

The social network has also said it would require advertisers to certify that they are complying with anti-discrimination policies and would allow the rights groups who sued to do testing on the platform to ensure the settlement was effective and that illegal targeting was blocked.

The ACLU noted research suggesting that ad targeting can replicate and exacerbate racial and gender biases as more people use the internet to find jobs, apartments and loans. The group alleged that the ad system ran afoul of longstanding federal civil rights laws, including the Fair Housing Act, the Equal Credit Opportunity Act and the Civil Rights Act.

The settlement resolves a number of lawsuits, including a complaint from the Communications Workers of America, a labor group that accused Facebook of allowing job ads that discriminated against older workers. The company will also pay roughly $5m as part of the settlement and agreed to implement the changes later this year.

Rashad Robinson, president of Color of Change, an advocacy group that has long scrutinized Facebook, called the reforms a “positive step” in a statement, but added: “Facebook has also repeatedly failed to follow through on its public promises.”

“This should be a signal to legislators and regulators that, despite previous claims to the contrary, it is possible for Facebook to control what happens on its platforms,” he said.

Facebook has continued to report record profits despite a steady stream of scandals over its misuse of people’s personal information and its negative impact on societies around the globe.

“Housing, employment and credit ads are crucial to helping people buy new homes, start great careers, and gain access to credit,” Sheryl Sandberg, Facebook’s chief operating officer, said in a statement. “They should never be used to exclude or harm people.”