(Reuters) - Liberal mayor Andrew Gillum pulled off a stunning upset in the Democratic primary for Florida governor on Tuesday, beating several better-funded rivals to set up a November showdown against a Republican aligned with President Donald Trump.

The Tallahassee mayor would be the state’s first black governor if he wins. He beat moderate Gwen Graham, a former U.S. representative and daughter of a prominent Florida politician, after running as an unabashed progressive who backed “Medicare for all,” impeaching Trump and standing up to the National Rifle Association.

Gillum, 39, will square off in November against Republican U.S. Representative Ron DeSantis, a conservative who won his primary by touting his closeness to Trump, in one of the country’s top governor’s races.

The November battle between progressives and conservative Trump Republicans will be closely watched by both parties for clues about the mood of voters and messaging ahead of 2020, when Trump could be seeking re-election against a liberal Democrat.

It also represents a change in direction for Florida Democrats, who have been out of the governor’s office in the state for 20 years; two more moderate candidates fell short against Rick Scott in 2010 and 2014.

Scott, now term-limited, won a primary contest to face incumbent Democrat Bill Nelson in a key Senate race in November.

The Florida contest came on the last big day of state nominating contests before the Nov. 6 elections, when Democrats will try to pick up 23 seats in the U.S. House of Representatives and two seats in the Senate to gain majorities and slam the brakes on Trump’s legislative agenda.

In Arizona, Republicans nominated U.S. Representative Martha McSally, an establishment favorite, in a three-way Senate primary that became a battle to prove who was most loyal to Trump.

Slideshow ( 15 images )

BIG SURPRISE

Gillum’s win was a surprise, as he trailed Graham in the polls for much of the race but surged in the final stages with the backing of liberal U.S. Senator Bernie Sanders and high-profile liberal donors like George Soros and Tom Steyer.

Several other candidates were also competing for the nomination, including former Miami Beach mayor Philip Levine, who, along with Graham, outspent Gillum.

Gillum emphasized his background as the son of a bus driver and construction worker and pledged to galvanize younger and minority voters who often sit out midterm elections. His strongest performance was in the state’s largest metro areas, with big margins in counties that include Jacksonville, Miami and Tampa, the three biggest cities.

“We have shown the rest of the country that we can be the David in the situation where there is a Goliath,” he told supporters after his victory. “That you can be the non-millionaire, you can come from a working class family, and you can make your way to the top.”

The conservative DeSantis easily won the Republican primary over state Agriculture Commissioner Adam Putnam by highlighting his enthusiastic loyalty to Trump, whose endorsement he won in recent weeks.

“I am not always the most popular guy in D.C., but I did have support from someone in Washington. If you walk down Pennsylvania Avenue, he lives in the White House with the pillars in front of it,” DeSantis, 39, told supporters after his win, adding that he had spoken to Trump.

In Arizona, which Trump won by 4 percentage points in 2016, former fighter pilot McSally had led for months in opinion polls over former state Senator Kelli Ward and controversial former Maricopa County Sheriff Joe Arpaio in the Senate nominating battle.

The Arizona contest to replace the retiring Jeff Flake is considered one of the two top takeover opportunities for Democrats, along with Nevada, and could be critical to the balance of power in the Senate in November.

Slideshow ( 15 images )

McSally was seen as a stronger general election candidate than either Ward or Arpaio, both hard-line conservatives. She has already launched advertising aimed at her Democratic opponent in November, U.S. Representative Kyrsten Sinema, who easily won nomination.

In a U.S. House primary in South Florida, Donna Shalala, a former health and human services secretary, beat a state legislator to win the Democratic nomination for the open seat of retiring Republican Ileana Ros-Lehtinen.

She will face Republican Maria Salazar, a Cuban-American journalist, in November, in a race that Democrats view as a top pickup opportunity.

Businessman Kevin Stitt won the Republican nomination for governor in Oklahoma in a primary runoff race against the former Oklahoma City Mayor Mick Cornett. Stitt had aligned himself with Trump and questioned Cornett’s allegiance to the president.

Only five states remain to pick candidates in early September before full attention turns to the November election, when all 435 House seats and 35 of the 100 Senate seats will be at stake.