By MATT VOLZ and NICHOLAS RICCARDI, Associated Press

HELENA, Mont. (AP) — When Donald Trump visited Montana last year ahead of the state's Republican presidential primary, technology entrepreneur Greg Gianforte was running on the GOP ticket for governor and made it a point to avoid his party's likely presidential nominee. Gianforte later reluctantly pledged support for Trump, but tried to distance himself from him during an unsuccessful campaign to unseat the state's Democratic governor.

Now, the multimillionaire Gianforte is trying to win an open seat in Congress and has gone all in on Trump.

Gianforte has co-opted the president's "drain the swamp" catchphrase, pledged to advance Trump's agenda and brought in Vice President Mike Pence and Donald Trump Jr. for campaign rallies ahead of Thursday's special election against Democrat Rob Quist. They're vying to replace Ryan Zinke, who became Trump's Interior Secretary in March.

Gianforte's shift from a hesitant backer of the reality show star's presidential bid to a candidate whose success or failure largely hinges on the president mirrors that of the Republican party.

"In the fall, it was just surviving the next 100 days and then he'll never be heard from again," GOP strategist Liam Donovan said of his party's gradual embrace of Trump. "Now, whatever Republicans felt about this guy before, he's a winner."

In an interview Wednesday, Gianforte said he isn't second-guessing his alliance with the president.

"I will always be on Montana's side and much more closely aligned with this administration than with (Democratic House Minority Leader) Nancy Pelosi," he said.

That could be risky for Gianforte and other Republicans who try to play the Trump card and then find themselves caught up in turmoil the president generates, like recent allegations that he divulged classified information to Russian diplomats and urged the FBI's director to drop an investigation into a former aide before firing him.

Trump's intense and loyal supporters may not flinch at the reports, said University of Montana political scientist Rob Saldin.

However, Gianforte's success may depend on how many of the Montana voters who gave Trump a 20 percentage point win over Hillary Clinton in Montana are in that loyalist bloc.

"There's a bit of a playing-with-fire element to this," Saldin said. "I think Gianforte and many Republicans recognize that, but it's a trade-off that at least for right now they're willing to accept."

Jake Eaton, a Montana Republican political consultant, said he recognizes the risk but said Gianforte is embracing Trump's message, not the person.

"I think that a lot of people across the political spectrum, regardless of what they think of the president as a person, are responding to what he's trying to do," Eaton said. "You know, not just uphold the status quo, but shake things up. I think that's a message that resonates with Montanans."

Gianforte's campaign had to walk a fine line when the House passed the Trump-backed American Health Care Act earlier this month. He was criticized for telling donors in a private call that he's "thankful" that the process to repeal and replace former President Barack Obama's health overhaul is underway, but made public a statement saying he would not have voted for the bill because he would have wanted more time to study it.

The health care bill is the clearest sign of how Gianforte's allegiance with Trump runs counter to the interests of Montana voters, said state Democratic Party Executive Director Nancy Keenan.

"I think that they don't want somebody else in Congress who's just going to be a rubber stamp, especially on issues like health care," she said.

Five months ago, when Gianforte lost to incumbent Democratic Gov. Steve Bullock, he tried to keep Trump from becoming an issue in his own campaign.

Before the Republican primary, Gianforte declined to attend Trump's one rally in Montana — and did not mention Trump's name in a statement welcoming the candidate to Montana.

Even after Trump won the GOP nomination, Gianforte was a reluctant supporter. He said in November that Trump said "obnoxious" things — but that he was backing him because he wanted Trump to pick the next U.S. Supreme Court nominee.

Then Election Day came, and more than 43,000 people who voted for Trump did not vote for Gianforte for governor, making him the only Republican running for a statewide election to lose that day.

"At that time, it appeared that Trump was a ticking time bomb and threatened to tear down anyone who was associated with him," Saldin said. "I think what is different now is that Gianforte looked at that race from the fall and concluded that the reason he didn't win, the reason he's not governor now, is there are a lot of people who voted for Donald Trump and voted for (former congressman) Ryan Zinke, but didn't vote for Greg Gianforte."

Trump in January chose Rep. Ryan Zinke to be Secretary of the Interior, opening up Montana's statewide congressional seat, and Gianforte jumped in. His Democratic opponent, Quist, is a singer, guitarist and award-winning songwriter.

Now Gianforte is an ebullient booster of the president.

"I'm running because you need a strong voice back in Washington," he told a crowd in East Helena earlier this month during an appearance with Donald Trump, Jr. "I want to help Donald Trump drain the swamp back there."

Washington D.C.-based Republican pollster Frank Luntz said Montana voters are generally conservative but like straight-talking mavericks like Trump and have previously embraced Democrats willing to buck conventional wisdom.

Democrats were always going to link Trump to Gianforte anyway, Luntz argued, and it makes sense for the candidate to make the comparison on his own terms.

"Montana is true Trump country," Luntz said. "I'm not surprised this guy would embrace Trump."