WASHINGTON — It wasn't even close.

Voters in North Carolina's largest county, which includes Charlotte, ousted their sheriff last week in a Democratic primary fought over immigration and criminal justice reform.

Advocates like the American Civil Liberties Union, which invested an unusually large amount of money in the race, hope to use it as a model as they look for ways to resist the Trump administration's immigration crackdown at all levels of government.

"We are absolutely seeking to put folks on notice," said Ronald Newman, the director of strategic initiatives for the civil liberties group.

The ACLU spent $175,000 in Mecklenburg County — almost three times the amount the winner on Tuesday raised in the first quarter of the year — helping to turn around a race that internal polling showed was the incumbent's to lose.

Garry McFadden attends the 2017 Inspire A Difference Honors Event in New York on Nov. 2, 2017. Gilbert Carrasquillo / FilmMagic file

Garry McFadden, a retired homicide detective who has been recognized by former President Barack Obama, won the three-way primary on Tuesday with 52 percent of vote.

Incumbent Sheriff Irwin Carmichael came in a distant third, with 20 percent of the vote, blaming "outside influences" and the immigration issue for his loss, even as he defended his policies.

There is no Republican on the ballot in the general election, so McFadden is effectively sheriff-elect.

The issue at the center of the campaign was an immigration program known as 287(g), in which local law enforcement agencies partner with Immigration and Custom Enforcement (ICE) to turn over undocumented immigrants arrested on unrelated crimes.

The program has taken on new significance as ICE steps up its raids under Trump and cities in blue states rush to declare themselves "sanctuary" cities.

Carmichael defended Mecklenburg County’s participation in the program, even appearing on Fox News in March to push back on critics who "say that we're ripping families apart."

"I always tell everyone, you will never ever encounter this program unless you are arrested and charged with a crime," he said.

McFadden, who is African-American, ran on a pledge to end local participation in the 287(g) program, improve police transparency, and enhance conditions at the jail run by the department.

He blames the program for creating roadblocks in several murder cases that remain unsolved, arguing that some witnesses refuse to cooperate with police out of fear they'll be put on ICE's radar.

"The witnesses are scared," he told NBC News. "We can make progress, but we need to have the community involved."

The ACLU, which only started to get seriously involved in elections after Trump’s unexpected victory, does not support or oppose candidates. Instead, it made a scorecard in this contest explaining where each sheriff candidate stood on key issues like immigration, and advocated for its own stance against the 287 (g) program, using phone banks, canvasses, and radio and digital ads to get the word out.

As Democratic pollster Mark Mellman ‏noted, the Democratic-leaning voters in big cities increasingly want their local officials to stand up to Trump, even in the South.

Sheriff Carmichael's massive defeat in Mecklenburg Cty NC sends a strong message to local law enforcement nationwide:



Cooperate with Trump's deportation squad and voters will punish you #ACLU — Mark Mellman (@MarkMellman) May 9, 2018

And while criminal justice reform may have stalled in Washington, advocates are notching victories on the local level.

"These decision are made 100 times more frequently by a sheriff, or DA, or police chief than they are by an individual member of Congress," said the ACLU's Newman. “On a pure impact-per-dollar perspective, it’s where you can have more impact."

Last year, Philadelphia elected reformist District Attorney Larry Krasner, while a liberal won a seat on the Wisconsin Supreme Court for the first time in years. Later this month, a candidate favored by reformers is favored to advance in the runoff for sheriff of Dallas County in Texas.

They also hope the outcome is a sign that immigration can be a political winner as Republicans play up fears of undocumented immigrant gangs like MS-13 in campaign ads this year.

McFadden, who once hosted a true-crime TV series based on his career and earned praise from Obama in the wake of the Black Lives Matter Movement, has big plans.

"What I'm going to do here is just going to be totally different," he said. "Now I have a sandbox big enough for all my toys."