President Donald Trump pardoned former Maricopa County Sheriff Joe Arpaio on Friday night — a controversial move to aid an early endorser who in many ways pioneered Trump’s brand of anti-immigrant politics.

Pardoning Arpaio — who was convicted of contempt of court in July for continuing to engage in aggressive immigration enforcement in defiance of a 2011 court order, before he is even sentenced — was an unusual move, to say the least. But it makes a tremendous amount of sense for Trump.

Not only is the president doing a favor for Arpaio, who helped validate Trump among the immigration hardliners who have since become a large share of his base; it sends a powerful message to sheriffs around the country who are worried that cooperating with federal immigration authorities could get them into trouble with the courts as well.

With the pardon, Trump mobilized immigrants-rights groups and made establishment Republicans nervous. It’s the kind of culture war milieu in which Trump thrives.

Arpaio was convicted of violating a judge’s order by doing something the Trump administration’s trying to pressure sheriffs around the country to do now

In the mid- to late-2000s, the federal government began to ramp up immigration enforcement to an unprecedented degree — by relying on cooperation with local law enforcement. And Sheriff Joe Arpaio was the face of local enforcement of federal immigration law.

He called himself “America’s Toughest Sheriff.” He gave celebrity tours of his famous “tent cities” for housing unauthorized immigrants and gifted guests with commemorative pairs of the pink underwear he made inmates wear. He bragged about the results of his “sweeps” — local immigration raids to round up unauthorized immigrants and hand them over to Immigration and Customs Enforcement (ICE).

Those sweeps, in particular, raised questions about how exactly Arpaio and his deputies were determining who to apprehend for immigration offenses — in other words, whether they were just profiling Latino residents of Maricopa County. In 2007, he was sued for civil-rights violations by a few Latino residents who were stopped by deputies (and sometimes detained for hours) on suspicion of being in the US without papers, apparently because of their ethnicity.

In 2011 (shortly after President Barack Obama’s Justice Department released a report finding that the Maricopa County Sheriff’s Office engaged in systematic racial profiling of Latinos) the judge in the racial profiling lawsuit issued an injunction preventing Arpaio from apprehending or detaining anyone purely on the basis of being a suspected unauthorized immigrant or turning such people over to federal agents.

In 2013, Arpaio officially lost the civil suit. But by that point, it had become clear that his department hadn’t actually been complying with Judge Murray Snow’s 2011 injunction. They’d continued to engage in immigration “sweeps,” turn people over to ICE (or, when ICE stopped accepting detainees from Arpaio’s deputies, Border Patrol), and hold suspected immigrants in jail after they’d otherwise be released for federal agents to pick them up.

After a series of hearings about the Maricopa Sheriff’s Office’s failure to comply with the 2011 order, Judge Snow cited Arpaio and a handful of his subordinates for civil contempt of court in 2015. Then, in 2016, he asked the US Attorney’s Office to charge Arpaio and three others with criminal contempt — which someone can only be convicted of if it’s shown they were willfully refusing to obey the court order, not just failing to make sure it was obeyed.

Arpaio claimed that he wasn’t deliberately disobeying Judge Snow’s order, he just hadn’t understood it properly — and besides, any violations were the fault of his underlings. Judge Snow didn’t buy it. For one thing, witnesses testified that Arpaio and underlings had directed them not to change internal policies after the court order. For another, Arpaio himself, during his frequent media appearances, often said that the department was just doing what it had always done. And then there was the fact that Arpaio had attempted to dig up dirt on Judge Snow himself (including having a detective investigate Snow’s wife).

By the time Arpaio was convicted in August 2017, however, there was a new sheriff in town — both in Maricopa County, where he’d been booted from office in 2016 (thanks in part to the county’s growing Latino electorate and in part to fatigue with Arpaio’s legal troubles) and in the United States, where Trump had been installed to take the same sort of tough-talking, disdainful-of-niceties, law-and-order approach to immigration around the country that Arpaio had taken in Maricopa County for all those years.

Arpaio understood, before Trump did, that law and order “toughness” doesn’t mean you actually have to conform to the laws

Sheriff Arpaio played a key role in validating Donald Trump, whose candidacy was initially seen as a joke, as the champion of hardline immigration policies and the cultural anxieties that came alongside them. Trump’s first truly major campaign rally, in August 2015, was in Phoenix with Arpaio and some of the “Angel Moms” (mothers of people killed by unauthorized immigrants) he would continue to co-opt as a candidate and president. Arpaio formally endorsed Trump in January 2016 — before a single primary vote had been cast. He took a gamble, and he won.

So it makes sense that Trump, who has some apparent loyalty to people who supported him back when he was one of 17 Republican presidential candidates, would think warmly of Arpaio. But the endorsement isn’t really the basis of their simpatico. It’s just an acknowledgment of the political truth that Trump is engaging in exactly the same brand of politics that Arpaio pioneered a decade earlier. As politicians, they used tough-on-crime rhetoric and breaches of “political correctness” to give the impression of sticking up for law and order; as government executives, they exercised their power to the greatest possible extent, without a ton of attention paid to the rule of law.

Like Trump, Arpaio communicated toughness through big, theatrical stunts — raids conducted with armored vehicles, the pink underwear, the tent cities — that often happened to violate the rights of their targets. (The tent cities were ultimately shut down after being cited as violations of the Eighth Amendment prohibition against “cruel and unusual punishment.”) His “law and order” policies weren’t successful as anti-crime measures (911 response times went up hugely during the heyday of Arpaio’s sweeps), but succeeded in terms of targeting and victimizing the intended people.

In Arizona — a state with a fast-growing Latino population, but also a substantial population of older white residents who had often moved to Arizona from places that hadn’t had many Latinos — anxieties about demographic and cultural change were acute, and Arpaio capitalized on them. By the mid-2010s, those anxieties had percolated through much of the rest of the country as well, and Arpaianism was ready to go national — in the form of Trump.

But when it came to the Maricopa County Sheriff’s Office obeying the laws as well as enforcing them, Arpaio was, at best, uninterested. His internal-affairs office, as Judge Snow found, was more a task force to pursue grudges than an effort to root out misbehavior among deputies. He’s been cited for systematic abuses of power in trying to get his enemies brought up on criminal charges — including local judges, members of the Maricopa County Board of Supervisors, and the former mayor of Phoenix.

In other words, his August conviction for contempt of court didn’t come out of the blue. It was a predictable consequence of the way he’d run his department — guided by a philosophy that as long as law-enforcement officials were grabbing headlines by going after undesirable people, the public wouldn’t care so much about how it was done.

Pardoning Arpaio just sent a strong message to other sheriffs: Don’t worry about the courts

The Trump administration has spent its first several months in office steadily ramping up immigration enforcement. But it’s running into a couple of big obstacles — and one of them is that many local sheriffs are wary of holding immigrants for ICE pickup.

Scooping up unauthorized immigrants who’ve been booked into local jails is an important ICE strategy: It allows them to claim they’re going after “criminal aliens,” without having to do the work of tracking anyone down or causing the outcry they get for conducting home raids. For all the administration’s complaints about “sanctuary cities,” the linchpin of this strategy isn’t actually city police forces: it’s county sheriffs, who operate the overwhelming majority of jails.

But many sheriffs are worried that holding people after they’d otherwise be released from jail, in order for ICE agents to pick them up, could get them in trouble with the courts for violating the Fourth Amendment.

“If we violate the law by doing what they ask us to do, we’re subjecting ourselves, no question, to civil liability and civil rights violations,” sheriff Bob Gualtieri of Pinellas County, Florida, told the Daily Beast’s Betsy Woodruff.

Gualtieri felt the Trump administration was oblivious to sheriffs’ concerns: He told Woodruff that officials “are saying, ‘What are you sheriffs doing? Why aren’t you cooperating?’ when they don’t know that it is clearly a problem and that we can’t do it.”

But other reports indicate that the administration is trying to solve the court problem by going around the courts — either by finding some way to “contract” sheriffs to hold immigrant detainees, as the New York Times reported on Monday, or by forcing the courts to decide that holding immigrants for ICE pickup is constitutional. (The administration is trying to intervene in a case in the Third Circuit, which includes Florida, to argue just that.)

There’s no guarantee that any of these strategies will work. The judicial branch — which has been less than deferential to the Trump administration — might hold firm in decreeing that people have a constitutional right to be released from jail when they have posted bail or been cleared, regardless of their immigration status.

That’s where the pardon power comes in. When Trump pardoned Arpaio of a criminal conviction he got for aggressively enforcing immigration law — including holding immigrants for ICE pickup — it sent a very clear message to the sheriffs like Gualtieri who are worried about court liability through the rest of the country. It indicates to them that if they get aggressive, and get in trouble with the law for it, the administration will have their back.