Montana Democratic Sen. Jon Tester, who at times has cozied up to Donald Trump as he tries to win re-election in a state the former president won by 16 points in 2020, has a long history of blaming Trump's popularity on racism. 

Tester, a lifelong farmer in Montana, has attempted to portray himself as a moderate in his Senate race against GOP challenger Tim Sheehy and has often touted how many times he has worked with Trump. However, Tester also has a long track record of denouncing Trump's support as a result of racism.

"As Trump spoke directly to rural America, most Democrats ignored it. Trump elevated white voters who had struggled for years as their mostly white communities suffered, as jobs and opportunities disappeared, and as businesses boarded up," Tester wrote in his 2020 book "Grounded: A Senator’s Lesson on Winning Back Rural America." 

"Trump turned to the old but effective strategy of lifting them up by pushing down others; by stirring up race-based fears and by giving angry and scared white voters permission to distrust other religions, other cultures, and other people. Trump tapped into the deep, gnarly root of racism in rural America. While we can’t uproot it overnight, we can’t ignore it either."

MONTANA SUPREME COURT RULING ON GREEN PARTY CANDIDATE COULD SPELL TROUBLE FOR JON TESTER, POLLING REVEALS

Jon Tester

Sen. Jon Tester arrives for the Senate Appropriations Subcommittee on Defense hearing on June 18, 2024. (Tom Williams/CQ-Roll Call, Inc via Getty Images)

In the same book, Tester claimed that a reason people stood by Trump no matter what was because "racial tension was its undercurrent."

"Trump brought charisma to the politics of millions of ordinary people, making himself relatable, tough, and believable," Tester wrote. "That’s why, when his own policies hurt American farmers and manufacturers, they marched in lockstep behind him, even despite their own self-interest. And there’s no denying that racial tension was its undercurrent."

Tester also told the New York Times in 2020 that he "can’t figure out" Trump’s appeal with rural America.

KEY SENATOR REPORTEDLY BEHIND HARRIS' RISE TO POWER WITHHOLDS HIS ENDORSEMENT FOR PRESIDENT

Jon Tester

Tester cast doubt on a recent unfavorable poll of his Montana race. (Reuters)

"There’s no doubt about it, he has an appeal in rural America," Tester said. "I can’t figure it out, but there’s no denying it. But I will also tell you I think there’s a long-term structural issue. And by the way, I’ve had this conversation with Chuck Schumer several times – that we have to do a better job developing a message so that rural Americans can say, ‘Yeah, those guys, they think like I do.’ Because that’s what Trump has right now.’"

Monica Robinson, a spokesperson for Montanans for Tester, told Fox News Digital that Tester "has been ranked one of the most effective and bipartisan senators because he’ll work with anyone to get things done for Montana."  

"No matter who is in the White House, Jon Tester always does what’s right for Montana," she added. "It’s why Jon has consistently stood up to the Biden administration on many issues – from securing the border to protecting Montana from bureaucratic rules that would hurt rural America – and it’s why President Trump signed more than 20 of his bills into law."

In a statement to Fox News Digital, National Republican Senatorial Committee spokesperson Maggie Aboud said, "Jon Tester hates Donald Trump, that’s why he routinely insults Trump’s voters and even called for Trump to be physically assaulted."

Election 2024 Trump

Former President Trump, speaks during a rally, Wednesday, Sept. 18, 2024, in Uniondale, New York. (AP Photo/Frank Franklin II)

CLICK HERE TO GET THE FOX NEWS APP

"Montanans can see right through Two-Faced Tester’s shameless attempts to tie himself to Trump now that he needs his voters." 

Many experts believe Montana is the best chance Republicans have to take back control of the Senate in 2024 and recent polling suggests Sheehy has a slight edge.

The Cook Political Report, an independent nonpartisan election handicapper, recently shifted the race from "toss-up" to "lean Republican," while Sabato's Crystal Ball at the University of Virginia's Center for Politics moved the race to "leans Republican."

Fox News Digital's Aubrie Spady contributed to this report