Facebook Inc. will no longer allow marketers buying housing, employment and credit-related ads to target ethnic groups, the social-media giant said Friday.

The company has been under pressure from U.S. lawmakers who have raised concerns that a Facebook feature allowing marketers to target users by “ethnic affinity” could be discriminatory.

Facebook...