Four former store detectives employed by CVS in New York filed a class-action lawsuit against the drugstore chain on Wednesday, accusing their bosses of ordering them to target black and Hispanic shoppers.

The lawsuit, filed in Federal District Court in Manhattan, also alleged that the detectives were fired after they complained about racial discrimination, against both customers and themselves.

The plaintiffs, all of whom are either black or Hispanic, contend in their suit that two supervisors in CVS’s loss-prevention department, overseeing stores in Manhattan and Queens, regularly told them to racially profile nonwhite shoppers. The suit says that one of the supervisors, Anthony Salvatore, routinely told subordinates that “black people always are the ones that are the thieves,” and that “lots of Hispanic people steal.” The second supervisor, Abdul Selene, frequently advised detectives, known at CVS as market investigators, to “watch the black and Hispanic people to catch more cases,” the suit said.

The supervisors also subjected the plaintiffs to discriminatory treatment, the suit said. When one plaintiff, Kerth Pollack, got into an argument with a store manager, Mr. Salvatore phoned him and demanded that he “get his black ass back to the store and apologize,” the suit said. A different store manager once instructed another plaintiff, Delbert Sorhaindo, to “hide like a monkey” to avoid being detected by potential shoplifters, the suit said.