“I won’t do it tonight because I don’t want to cause any controversy,” the president said Tuesday night at a campaign-style rally in Phoenix, after asking, “Was Sheriff Joe convicted for doing his job?”

“I’ll make a prediction: I think he’s going to be just fine,” Mr. Trump said.

Mr. Arpaio, 85, served for 24 years as sheriff of Maricopa County — which includes Phoenix — building a national reputation for harsh conditions in his county jail, and for his campaign against undocumented immigrants.

Mr. Arpaio had touted himself as “America’s toughest sheriff,” making inmates wear pink underwear and serving jail food that at least some prisoners called inedible. He was also at the forefront of the so-called birther movement that aimed to investigate President Barack Obama’s birth certificate.

The criminal conviction grew out of a lawsuit filed a decade ago charging that the sheriff’s office regularly violated the rights of Latinos, stopping people based on racial profiling, detaining them based solely on the suspicion that they were in the country illegally and turning them over to the immigration authorities.

A federal district judge hearing the case ordered Mr. Arpaio in 2011 to stop detaining people based solely on suspicion of their immigration status, when there was no evidence that a state law had been broken. But the sheriff insisted that his tactics were legal and that he would continue employing them.

He was convicted last month of criminal contempt of court for defying the order, a misdemeanor punishable by up to six months in jail.