The lawsuit has already cost taxpayers more than $50 million in legal fees and contributed to Arizona’s reputation for bias against immigrants.

Gov. Doug Ducey has worked to redefine the state’s relationship to Mexico, bruised by the immigration law signed by his predecessor that empowered the police to ask about the legal status of anyone whom they suspected of being in the country illegally. Sheriff Arpaio, meanwhile, has remained a loyal ally of Donald J. Trump, the Republican presidential nominee, amplifying his calls for a wall along the Southern border, paid for by Mexico.

Sheriff Arpaio has alternated between meek and defiant in and outside court, openly criticizing Judge Snow to reporters and often characterizing the racial profiling case against him as a political vendetta by the Obama administration.

“The truth will come out,” he said in a recent interview from Tent City here, where inmates are housed in recommissioned Korean War tents, exposed to this city’s torrid summer heat.

The case was filed in 2007 on behalf of Latino drivers who claimed they had been systematically targeted by sheriff’s deputies during traffic stops and immigration patrols. Judge Snow agreed, ordering changes in training and procedures, including a requirement that officers relay by radio the reason for each stop before approaching a driver.

But in May, the judge found Sheriff Arpaio and his top deputies in contempt of court, saying that they had “engaged in multiple acts of misconduct, dishonesty and bad faith” and “demonstrated a persistent disregard for the orders of the court.” His decision to ask the United States attorney’s office to bring criminal charges came despite Sheriff Arpaio’s apologies and pleas by one of his lawyers, Mel McDonald, last month in court.

“One thing I’m convinced, judge, is that you want to see the process succeed,” Mr. McDonald said. He listed reasons against a criminal referral — Sheriff Arpaio’s age (he is 84) and “long career in public service,” his apologies for disrespecting the court’s order, and the “hundreds, if not thousands of hours” already spent to comply with it.