PHOENIX — Sheriff Joe Arpaio, who made a name for himself as an unapologetic pursuer of unauthorized immigrants, was found in contempt of court here on Friday for willfully violating an order requiring his deputies to stop detaining Latinos based solely on the suspicion that they were in the country illegally.

In a 162-page ruling, Judge G. Murray Snow of United States District Court found that the sheriff had ignored advice from top commanders and his own lawyer and persistently publicized the pursuit and arrests of unauthorized immigrants because he believed those actions benefited his re-election campaign in 2012. Mr. Arpaio, 83, who has said he will run for a seventh term in November, has about $8 million in his campaign war chest, most of it donations from out-of-state residents who champion his tactics of immigration enforcement.

Judge Snow said Mr. Arpaio and three current and former aides at the Maricopa County sheriff’s office had engaged in “multiple acts of misconduct, dishonesty and bad faith” as they continued to racially profile Latinos in traffic stops and workplace raids.

Often, Latinos were turned over to federal immigration agencies even though they had not committed any state or federal crimes — and even though the agencies had not formally asked the sheriff’s office to do so. In his order, Judge Snow wrote that Mr. Arpaio and his aides — Chief Deputy Jerry Sheridan, retired Chief Brian Sands and Lt. Joe Sousa — “have demonstrated a persistent disregard for the orders of the court, as well as an intention to violate and manipulate the laws and policies regulating their conduct.”