TALLAHASSEE — Tallahassee Mayor Andrew Gillum upset a crowded field of well-funded candidates in Florida’s Democratic gubernatorial primary Tuesday, a step away from becoming the state’s first black governor. His surprise victory sets up a November showdown with Republican Rep. Ron DeSantis, a favorite of President Donald Trump.

Gillum’s victory could further energize black voters in a year when Democrats already are counting on high turnout among minorities to buoy the party in the November election. Gillum is the party’s third black gubernatorial nominee this year, along with Stacey Abrams in Georgia and Ben Jealous in Maryland.

DeSantis rode Trump’s endorsement to victory in the GOP race, underscoring the president’s broad appeal in Republican primaries. Trump cheered DeSantis’ victory on Twitter Tuesday night, writing: “Ron will be a fantastic Governor. On to November!”

DeSantis was one of several Republicans running in contests Tuesday in Florida and Arizona — both important political battlegrounds — who hoped that cozying up to the president would be rewarded by voters. Trump has thrust himself into the forefront of the midterm campaign in hopes of motivating his supporters and offsetting Democratic enthusiasm.

In Arizona, primary contests were shadowed by the death of Sen. John McCain. Though McCain was a towering figure who was elected to the Senate by Arizonans six times, the three Republican candidates running to replace his retiring seat-mate, Sen. Jeff Flake — including establishment favorite Rep. Martha McSally — aligned themselves more with the president than the longtime senator.

Arizona Gov. Doug Ducey planned to name a replacement to fill McCain’s seat after the primary.

Dozens of polling locations in Arizona’s largest county didn’t open on time and voters reported being turned away. Leaders in Maricopa County rejected calls to try to keep polls open later, saying it could confuse voters and delay returns. No problems were reported in other parts of the state.

Elsewhere Tuesday, GOP voters in reliably Republican Oklahoma backed mortgage company owner Kevin Stitt in a runoff for the gubernatorial nomination. Stitt won in part by criticizing his opponent as insufficiently supportive of Trump.

Trump surprised Florida Republicans late last year with his endorsement of DeSantis, and frequently tweeted about the lawmaker, one of his staunchest supporters in Washington. His backing helped push DeSantis past Agriculture Commissioner Adam Putnam, who has held elected office in Florida since 1996, quickly built up establishment support and raised millions of dollars.

Gillum came from behind in a crowded and diverse Democratic field. Former Rep. Gwen Graham, whose father, Bob Graham, served as governor, had been hoping to position herself to become the state’s first female governor.

Gillum, a favorite of progressives, spent the least of the five major Democratic candidates and had the smallest television presence. He often said he was the only candidate in the race who wasn’t a millionaire or billionaire, and won the endorsement of Vermont Sen. Bernie Sanders.

The winner of the Florida governor’s race will give his party an advantage in a key political battleground heading into the 2020 presidential campaign.

Current Florida Gov. Rick Scott is vacating the governor’s mansion to run for the U.S. Senate. He easily won his primary, setting up a showdown with Democratic Sen. Bill Nelson that is expected to be one of the nation’s most competitive races.

Democrats also eyed congressional pickup opportunities in Florida as they try to flip control of the U.S. House. One of their best chances is in South Florida, where Republican Rep. Ileana Ros-Lehtinen is retiring in a district that should favor Democrats.

Donna Shalala, who served as President Bill Clinton’s Health and Human Services secretary, claimed the Democratic nomination in Ros-Lehtinen’s district.

The primaries in both Florida and Arizona were closely watched for signs of how the political battlegrounds might tilt in the 2020 presidential election.

McCain’s death has highlighted anew the shift in the Republican Party since he captured the GOP nomination for president in 2008. His more moderate stance on immigration and his deciding vote last year against Trump’s efforts to repeal President Barack Obama’s health care law turned off many GOP voters.

A CNN survey in June found that 67 percent of Democrats had a favorable opinion of McCain, while just 33 percent of Republicans did.

Among those on the GOP Senate ballot in the state was former state Sen. Kelli Ward, who tried unsuccessfully to unseat McCain in 2016. When McCain’s family said last week that he was discontinuing medical treatment, Ward speculated in a later-deleted Facebook post that the announcement was intended to hurt her campaign for Flake’s seat.

Ward apologized Monday, saying she was bemoaning media coverage rather than the family’s announcement.

“I do understand how many could have misconstrued my comments as insensitive, and for this I apologize,” Ward said.

Also running for the Senate nomination was former Maricopa County Sheriff Joe Arpaio, the controversial immigration hardliner. Trump spared Arpaio a possible jail sentence last year by pardoning his federal conviction stemming from immigration patrols.

McSally, a fighter pilot turned congresswoman in the McCain mold, was hoping Ward and Arpaio split Arizona’s anti-establishment vote.

The winner of the GOP primary is likely to face Democratic Rep. Kyrsten Sinema, who had only token primary opposition. Sinema announced that she was pausing her campaign Wednesday and Thursday, when McCain’s body will lie in Arizona’s Capitol.

Sinema’s and McSally’s Senate runs also have created House openings in Arizona, a fast-growing and increasingly diverse state where Democrats are eager to gain a foothold. McSally’s district in particular is expected to be one of the most competitive House races in November’s general election.