Montana’s U.S. Senate race took a dramatic turn on Wednesday: A libertarian candidate endorsed his Republican opponent after an illegal campaign mailer tried to siphon votes from the GOP candidate and pave victory for the incumbent Democrat.

Republican Matt Rosendale is in a dead-heat race against Democrat Jon Tester, with polls showing the GOP candidate trailing within the margin of error. Fox News deems the race “leaning Democrat.”

But Libertarian Rick Breckenridge, who has no chance of winning the race, took an unprecedented step in Montana politics and endorsed Rosendale, saying he’s taking a stand against “dark money” in politics.

DEM SEN. TESTER CAMPAIGNS ON HUNTING, HASN'T HAD LICENSE IN 6 YEARS

The move came after an anonymous campaign mailer from an unknown group, which is a violation of state and federal election laws, went out to people in a bid to garner support for the Libertarian candidate and thus undermine Rosendale’s election chances.

“Matt Rosendale wants to use drones and patrols to spy on our private lives,” the mailer read. “Rick Breckenridge is a true conservative and opposes government intrusion into Montanans' private lives.”

It remains unclear who’s responsible for the mailer, but the tactic resembles the efforts by Democratic groups that supported Tester’s 2012 bid, where a mailer was sent out to promote another libertarian candidate.

Tester won that race by 4 percentage points thanks to the Libertarian candidate who received over 6 percent of the vote – just enough votes to swing the election if the votes had gone to the Republican candidate at the time.

KAVANAUGH CONFIRMATION BATTLE GALVANIZES MONTANA’S REPUBLICAN VOTERS, COULD SWING SENATE RACE

Breckenridge deemed the mailer an attempt to influence the election, prompting his endorsement of the Republican, even though he disagrees with some of his views.

“The reality is I'm only going to get 3 or 4 percent of the vote, and [Rosendale] has the character to combat this issue,” Breckenridge told the Associated Press. “I'm standing in unity and solidarity with Matt to combat dark money in politics.”

"The reality is I'm only going to get 3 or 4 percent of the vote, and [Rosendale] has the character to combat this issue. I'm standing in unity and solidarity with Matt to combat dark money in politics." — Libertarian candidate Rick Breckenridge

Rosendale accepted his opponent’s endorsement and went on to accuse the “allies of Tester” for distributing the “dark money mailer.”

Tester’s campaign denied responsibility and pushed back against the accusations.

“This is yet another lie from Matt Rosendale - our campaign had nothing to do with this mailer, and Jon believes all campaign expenditures should be disclosed,” Tester spokesman Chris Meagher said in a statement. “We condemn this mailer and any other efforts like it.”

The Associated Press contributed to this report.