HARRISBURG, Pa. (AP) — Doug Mastriano won the Republican nomination for Pennsylvania governor on Tuesday, beating eight other candidates and a party establishment that had tried to head off his nomination over fears that he is too extreme to win the general election in the presidential battleground.

Mastriano, a retired U.S. Army colonel and state senator since 2019 who was endorsed by former President Donald Trump, will face Democrat Josh Shapiro in the November election.

Mastriano, once viewed as a fringe candidate, spent almost nothing on TV ads and largely shunned interviews with independent news organizations. Mastriano beat a number of Republican rivals who outspent him and he suggested that he can again win a fall election where he will be outspent.

“We had the hardest-working campaign in this primary,” Mastriano told a cheering crowd in a Chambersburg event hall. “We’re going to have the hardest-working campaign in the general election.”

Democrats, meanwhile, were united behind Shapiro, the state’s two-term elected attorney general. Shapiro was uncontested on the primary ballot after wrapping up the endorsement of the state party and its top allies, including the AFL-CIO, and raising more than $20 million since early 2021.

Mastriano and Shapiro are vying for the right to succeed Democratic Gov. Tom Wolf, who is constitutionally term-limited after entering office in 2015. The winner in the fall general election is likely to share power with a Republican-led Legislature, where entrenched GOP majorities have controlled the floors for nearly all of the past three decades.

Shapiro helped cement his reputation with a landmark grand jury investigation into child sexual abuse coverups inside Pennsylvania’s Roman Catholic dioceses and defending Pennsylvania’s 2020 election result against attempts in court to overturn it by Trump and his allies.

His electoral success statewide and fundraising prowess cleared the field of rivals. Shapiro, 48, is a former state House member and county commissioner from Montgomery County.

Shapiro tested positive for COVID-19, his campaign said Tuesday. He was experiencing mild symptoms and was isolating at home, it said.

In a statement, Shapiro said he knows Pennsylvanians are worried right now, “and that’s why they need a governor they can count on and one who can meet this moment.”

He called Mastriano a “dangerous extremist who wants to take away our freedoms.”

Mastriano, 58, represents a Senate district based in conservative Franklin County on Pennsylvania’s southern border with Maryland.

On stage in Chambersburg, Mastriano said, “our No. 1 goal is first, is to restore freedom.”

In his campaign, he connected with far-right GOP voters through appearances on conservative broadcasters, a tireless ground campaign that dotted the state with his yard signs and endorsing conspiracy theories, including Trump’s unsubstantiated claims that Democrats stole the 2020 presidential election from him.

He also emphasized his military background, Christian beliefs and hard-line conservative positions on abortion and guns.

Mastriano was well on his way to victory when Trump endorsed him on Saturday. In the final days of the campaign, party officials tried to consolidate support around former U.S. Rep. Lou Barletta, the Trump-endorsed nominee for U.S. Senate in 2018, in a long-shot bid to defeat Mastriano.

Mastriano slammed it as a “backroom deal.”

In 2020, Mastriano became a rising force in Pennsylvania’s right-wing politics, gaining a following by leading anti-shutdown rallies during the early days of the pandemic to protest Wolf’s orders to wear masks in public, close down non-essential businesses and educate school children remotely.

Mastriano went on to pad his support among hardcore Trump backers by working with the former president to overturn his loss in 2020’s election in the presidential battleground state. That earned Mastriano a subpoena from the U.S. House committee investigating the Capitol riot on Jan. 6, 2021.

He later organized bus trips to the U.S. Capitol for Trump’s Jan. 6 “Stop the Steal” rally, where he was seen in footage with his wife passing through breached barricades set up by Capitol Police.

Trump endorsed Mastriano over the protests of many party officials who feared he cannot win over the moderate voters necessary to prevail in politically divided Pennsylvania.

Shapiro’s campaign, meanwhile, closed the primary campaign by running a TV ad portraying Mastriano as extreme and saying that if Mastriano wins, “it’s a win for what Donald Trump stands for.”

Mastriano has insisted to supporters that he is not extreme and that his platforms — including eliminating mail-in voting, expanding gun rights, banning abortion and banishing school property taxes — enjoy broad support.

Rather, he says Democrats — including President Joe Biden — are far-left radicals while the Republican “swamp” was trying to defeat him.

Republican voters had to choose from among nine names on the ballot for governor, even though two said they had ended their campaigns and endorsed Barletta as part of a last-ditch attempt to help defeat Mastriano.

Barletta had picked up a number of endorsements by current and former Republican officeholders, including members of Congress.