First came disclosures of racist and homophobic text messages exchanged by officers of the San Francisco Police Department. That was followed by the discovery that sheriff’s deputies had been gambling on forced fighting matches between inmates at a city jail.

Then on Thursday, the San Francisco district attorney announced that he was expanding the investigation of the city’s police and sheriff’s departments to examine whether those agencies have a deep-seated culture of systemic bias that has led to unlawful arrests or prosecutions.

In a year in which many of the nation’s major cities have been rocked by protests after the fatal police shootings of unarmed African-Americans, the broadened inquiry made clear that even a city known for its liberal politics can be buffeted by accusations that its officers behaved in a racially biased manner.

African-Americans in San Francisco have complained for years about harassment and the use of excessive force by the police. And while African-Americans make up about 5 percent of the city’s population, they account for half of its arrests and jail inmates, and more than 60 percent of the children in juvenile detention, according to city statistics.