After a bruising and bitter campaign to replace retiring Sen. Lamar Alexander of Tennessee, Republicans picked the candidate backed by President Trump while Democratic voters shunned the party pick in a surprise upset.

Bill Hagerty, Trump’s former ambassador to Japan, won the endorsement of the president, who had tweeted his support and appeared at a tele-town hall in support of the candidate Wednesday night. With Trump since 2016, Hagerty served as a high-dollar fundraiser for his campaign and later on Trump’s transition team.

But Nashville surgeon Manny Sethi gained traction in the primary by challenging Hagerty’s conservative credentials, pointing to his early support for Jeb Bush in 2016 and his prominent role in Mitt Romney’s 2012 presidential campaign.

Trump noted the victory for the candidate he endorsed as he arrived in Bedminster, N.J., from Ohio on Thursday night, walking over to the media to say: “Hagerty won the race in Tennessee. They just announced.” The Associated Press had called the race just a few minutes earlier.

Democrats, who had not considered the race a top pickup opportunity, were dealt a surprise as environmentalist Marquita Bradshaw defeated Army veteran and attorney James Mackler. That marked the first primary loss for a candidate endorsed by the Democratic Senate Campaign Committee since 2010.

Mackler had briefly run for Senate in 2018 before former governor Phil Bredesen jumped into the race. Mackler bowed out, and Bredesen repaid him with an endorsement when Mackler ran again.

With national party support, Mackler had raised $2.1 million for his race. Bradshaw did not file a report with the Federal Election Commission, making it unclear how much she raised or spent. A Memphis activist who traveled to Ferguson, Mo., to join the 2014 protests there, Bradshaw dominated the vote in her city and across western Tennessee.

“People of color, Black people, Brown people, Indigenous people and poor White people are not experiencing the same set of laws as everybody else when it comes to the environment,” Bradshaw told Nashville’s WPLN News last month.

Mackler, who had entered the race first, reacted to Bradshaw’s entry by insisting “there’s no longer a pathway forward for a Democratic primary challenger,” according to the Nashville Scene.

In the 5th District, Democratic Rep. Jim Cooper fended off Keeda Haynes, a public defender who was formerly incarcerated for a crime she has denied committing. Haynes spent less than $100,000 on her race but was winning more than 40 percent of the vote.

On the GOP side, the primary received national media attention and big-dollar donors. Hagerty had raised $8.3 million as of July 17 and has about $2.7 million in cash on hand, according to opensecrets.org. Sethi raised $4.6 million, which includes a $1.9 million contribution from his own pocket. He had about $386,000 in cash on hand.

Running as the outsider candidate against the Washington establishment — #MannyvstheMachine was his hashtag — helped Sethi earn the endorsements of Republican Sens. Ted Cruz of Texas and Rand Paul of Kentucky. Cruz visited the state to campaign for Sethi, telling a crowd, “We need a conservative warrior in the Senate representing Tennessee.”

Despite Sethi’s pitch as the better ally of Trump, the president stood by Hagerty, tweeting that he’s “an outstanding man and one of the best Ambassadors ever (Japan) . . . He loves Tennessee and loves our Country. We need him badly in Washington. He has my Complete and Total Endorsement!”

Both candidates rejected mandates on mask-wearing. Last week, they attended a Republican Party dinner event with hundreds in attendance where, according to photos, many were maskless. On Wednesday it was revealed that one of the guests had since tested positive for the novel coronavirus.

The state saw an increase in early and absentee voting, with about 578,250 people casting votes early or by absentee ballot as of Aug. 1, compared with about 251,380 at the same point in 2012, according to data published by the secretary of state’s office. The data did not break down how many votes were early in-person and how many were by absentee ballot.

Voting in the state appeared to proceed smoothly Thursday, an improvement over the state’s March presidential primary, when voters encountered lines and polling locations were shuttered by damage from a tornado.

Although anyone could vote absentee for Thursday's primary, rules for absentee voting will be tightened for Tennesseans in November. The state Supreme Court ruled Wednesday that fear of coronavirus exposure at in-person voting locations does not count as a blanket excuse to obtain an absentee ballot for the general election. Only voters with an excuse permitted under state law may vote by mail, the court ruled.

Elise Viebeck contributed to this report.