WASHINGTON—Facebook was charged with discrimination by the U.S. Department of Housing and Urban Development because of its ad-targeting system.

HUD said Thursday that Facebook is allowing advertisers to exclude people based on their neighborhood by drawing a red line around those neighborhoods on a map and giving advertisers the option of showing ads only to men or only to women. The agency also claims Facebook allowed advertisers to exclude people that the social media company classified as parents; non-American-born; non-Christian; interested in accessibility; interested in Hispanic culture or a wide variety of other interests that closely align with the Fair Housing Act’s protected classes.

HUD, which is pursuing civil charges and potential monetary awards that could run into the millions, said that Facebook’s ad platform is “encouraging, enabling, and causing housing discrimination” because it allows advertisers to exclude people who they don’t want to see their ads.

The claim from HUD comes less than a week after Facebook said it would overhaul its ad-targeting systems to prevent discrimination in housing, credit and employment ads as part of a legal settlement with a group that includes the American Civil Liberties Union, the National Fair Housing Alliance and others.

The technology at the heart of the clashes is what has helped turned Facebook into a goliath with annual revenue of close to $56 billion.

It can offer advertisers and groups the ability to direct messages with precision to exactly the crowd that they want to see it. The potential is as breathtaking as it is potentially destructive.

Facebook has taken fire for allowing groups to target groups of people identified as “Jew-haters” and Nazi sympathizers. There remains the fallout from the 2016 election, when, among other things, Facebook allowed fake Russian accounts to buy ads targeting U.S. users to enflame political divisions.

The company is wrestling with several government investigations in the U.S. and Europe over its data and privacy practices. A shakeup this month that ended with the departure of some of Facebook’s highest ranking executives raised questions about the company’s direction.

The departures came shortly after CEO Mark Zuckerberg laid out a new “privacy-focused” vision for social networking. He has promised to transform Facebook from a company known for devouring the personal information shared by its users to one that gives people more ways to communicate in truly private fashion, with their intimate thoughts and pictures shielded by encryption in ways that Facebook itself can’t read.

However, HUD Secretary Ben Carson said Thursday that there is little difference between the potential for discrimination in Facebook’s technology, and discrimination that has taken place for years.

“Facebook is discriminating against people based upon who they are and where they live,” Carson said. “Using a computer to limit a person’s housing choices can be just as discriminatory as slamming a door in someone’s face.”

Facebook did not immediately respond to a request for comment early Thursday.