San Francisco police officers sent dozens of racist and homophobic text messages in the past several months, even as another group of officers was being investigated by prosecutors for having traded similar messages, the city’s district attorney said Thursday.

The disclosure of the new round of text messages, which includes derogatory references to blacks, Asians, lesbians, gays and transgender people, comes as the Police Department is under federal investigation after complaints that some officers routinely behave in a racially biased manner.

Along with dozens of other police departments around the nation, the San Francisco police — who work in one of the nation’s most culturally diverse cities — have come under scrutiny during the past year.

Officers have been accused of using unnecessary deadly force and brutality, and of focusing enforcement efforts on black neighborhoods while ignoring similar infractions elsewhere. Police critics, including many among the city’s dwindling black population, have held protests and called for the resignation of the police chief, Gregory P. Suhr.