Sherry Yoksh of Cheyenne, Wyo., gets a voting card from Ruth Carol at Yellowstone Baptist Church during the state’s primary election Aug. 21. (Jacob Richard Byk/Wyoming Tribune Eagle via AP)

Wyoming Republicans nominated state treasurer Mark Gordon for governor on Tuesday, in a blow to President Trump after his eleventh-hour endorsement of investor Foster Friess.

With more than 99 percent of the vote counted, Gordon, 61, was declared the winner over five other Republicans, including Friess, who was backed by Trump after securing the support of multiple conservative activists and the president’s eldest son.

Democrats nominated Mary Throne, a former state legislator, who became the party’s 10th female nominee for governor in this cycle.

But Democrats concede that Gordon, who was outspent more than 2 to 1 by Friess, would be the favorite to win. Gordon ran as a capable successor to Gov. Matt Mead, a Republican who has been broadly popular, and who had appointed Gordon to the high-profile treasurer job.

Gordon’s win, however, ended a string of successful endorsements for the president in Republican primaries. In Kansas, Michigan and South Carolina, Trump has endorsed Republicans with the same pitch — that they are “strong on crime, borders & 2nd amendment” — and celebrated when they won. While several were leading in the polls before Trump endorsed, the Wyoming race had been considered a toss-up.

Gordon had emphasized his government background and work on a family cattle ranch.

“When you work with animals, you have to know what you’re doing,” Gordon said in one TV spot. “Same with government.”

Friess, a Wisconsin-born investor, didn’t emerge as a force in conservative politics until 2011, when he bankrolled a super PAC supporting presidential candidate Rick Santorum. He stepped up his activity after that, becoming a member of the Koch donor network and providing seed money to conservative media and activist groups.

“He wrote the first $10,000 check to get [us] started and as they say, ‘the rest is history,’ ” tweeted Charlie Kirk, the founder of Turning Point USA, a conservative college organization.

But Friess made no serious political moves of his own until last year, when he began exploring a U.S. Senate run. In April, he abruptly announced a bid for governor, throwing a curveball into a race that had been seen as an easy win for Gordon. Since then, he has packaged himself as an incorruptible outsider.

“I have no business to manage. I don’t have a single calf to brand. I’m available,” Friess said at a debate on Aug. 1. “I’m not taking a single penny from special interest groups, and I’m giving my salary away.”

Throne, the Democratic gubernatorial nominee, said in an interview that a serious campaign could lift the party and be competitive in November.

“In Wyoming, we value independence, and we value putting our state ahead of either party,” she said. “When one party is in charge, everything that happens, happens behind closed doors.”

Republicans also voted in what served as a referendum on Sen. John Barrasso, who faced a GOP primary challenge from Dave Dodson, an investor who has spent more than $1 million on his campaign and pledged to “put Wyoming first” by bringing jobs back to the state.

Barrasso glided to victory Tuesday after blistering Dodson with TV ads highlighting the businessman’s past donations to Democrats — and filing a complaint with the Federal Election Commission because Dodson’s ads did not include the proper disclaimers.

“Ask David Dodson, who does he really put first?” says a narrator in Barrasso’s ads.

Democrats picked businessman Gary Trauner, who narrowly lost a 2006 House race, to challenge Barrasso. They also were expected to select energy consultant Greg Hunter to challenge Rep. Liz Cheney (R).

Alaskans also went to the polls Tuesday, with both major parties eagerly angling to take back the state from the country’s only elected independent governor, Bill Walker. Democrats selected former senator Mark Begich, while Republicans picked former legislator Mike Dunleavy.

Democrats picked education activist Alyse Galvin to challenge Rep. Don Young (R) in the general election.

In both states, more was at stake lower on the ballot. Democrats hoped that more competitive top-of-the-ticket races in November would pay benefits in lower-level races.

In Alaska, they hoped to increase their numbers in the state legislature, where a quarter of incumbents are retiring. In 2016, as the party underperformed in other states, Democrats in Alaska won a working majority in the state House.

In Wyoming, neither the Senate nor the governor’s race is viewed as a national Democratic priority. But state Democrats, like those in Alaska, are hoping to increase their wins in legislative races After the 2016 election, they hold just nine seats in the 60-member state House, and three seats in the 30-member state Senate. The party has not won a statewide Wyoming election since 2006.