The sheriff for metropolitan Phoenix trounced three rivals Tuesday to win his Republican primary in what could be the toughest campaign in his 24 years in office as he faces a storm of legal troubles stemming from his immigration patrols.

Sheriff Joe Arpaio easily beat former Buckeye Police Chief Dan Saban and two lesser-known Republicans. Arpaio has raised a staggering amount of money for a local sheriff's race — $11.3 million and counting, most from people living in other states.

The 84-year-old lawman moves on to face the race's sole Democrat, retired Phoenix police Officer Paul Penzone, in the Nov. 8 general election. Penzone lost the 2012 sheriff's race by six percentage points, marking his second closest election in Arpaio's political career.

Arpaio is seeking a seventh term as he experiences the worst legal troubles in his career.

Over the past four years, a federal judge has ruled that Arpaio's officers racially profiled Latinos during traffic stop, and the sheriff was found in civil contempt of court for defying court orders in the case.

The judge recently recommended that Arpaio face criminal prosecution over the contempt case for prolonging his immigration patrols months after the court ordered them stopped. He could be sent to jail if he is found in violation of criminal contempt-of-court charges.

Arpaio rose to national political prominence by cracking down on illegal immigration and by jailing inmates in tents in triple-degree temperatures and dressing them in pink underwear.

The sheriff has been criticized for saddling taxpayers with huge legal bills by creating contentious immigration and jail policies that were later challenged in court. The taxpayer costs from the racial-profiling case alone are projected to reach $54 million by next summer.

In recent years, Republican presidential candidates have sought Arpaio's endorsement.

He has thrown his support this year behind Donald Trump and stumped for the GOP nominee during his visits to Arizona, including a huge gathering in March in the affluent Phoenix suburb where the sheriff lives. He also gave a speech at the Republican National Convention in which he said Trump would prevent immigrants from sneaking into the country.

He is scheduled to speak before Trump on Wednesday as he delivers a much-anticipated immigration speech in Phoenix.

Arpaio has seen his popularity wane over the past four elections. The 2012 race marked his second-closest election as sheriff; he defeated Penzone by 6 percentage points.

Still, the $11.3 million in campaign money Arpaio has raised far exceeds his opponents' fundraising. Saban raised $30,000, while retired sheriff's deputy Wayne Baker brought in $40,000 and former sheriff's posse volunteer Marsha Hill reported $15,000.

Arpaio's challengers have promised to bring more professionalism and less self-promotion to the job. Arpaio's critics say he wastes taxpayer money by pursuing flimsy cases that get him publicity but ultimately get thrown out and result in costly lawsuits.