Democratic candidate Rob Quist, left, and Sen. Bernie Sanders, I-Vt., greet supporters at a campaign rally Saturday in Butte, Mont. (Justin Sullivan/Getty Images)

For months, Democrats were careful not to promise too much about Montana’s May 25 special election. Hillary Clinton had lost the state by 20.2 points. Rob Quist, the folk-singing Democratic candidate for Congress, had never run for office before. Losing a close race would grant a moral victory; raising the stakes and losing might give Republicans a boost.

On Saturday, in front of 3,000 cheering voters at this Democratic city’s Civic Center, Sen. Bernie Sanders (I-Vt.) raised the stakes.

“The eyes of the country, actually eyes all over the world, are on the great state of Montana,” said Sanders. “People are asking: Is it possible for working people, for seniors, for ordinary people, to come together and successfully defeat a candidate of the millionaires? They’ll know it if you do it in Montana.”

Sanders’s much-anticipated visit kicked off the final stretch of voting in a race that has become closer than either party might have expected. Quist, 69, has raised more than $5 million, nearly doubling the last Democratic candidate for Montana’s sole House seat. Millions of dollars have poured in for Greg Gianforte, 56, a software entrepreneur who won the GOP nomination after narrowly losing the 2016 race for governor — running nearly 10 points behind Donald Trump.

The result, in the final days, is a dogfight between Democrats who’ve bet on a flawed but compelling populist, and Republicans who worked hard and early to protect their structural advantage — and exploit Quist’s flaws. And the final votes will be cast just hours after the Congressional Budget Office reveals the new score for the American Health Care Act, which Quist has campaigned hard against and Gianforte has struggled to defend.

Sanders’s four-city barnstorming, which put the Democrat in front of more than 10,000 total voters, came after plenty of ballots had been cast. As of May 18, 351,681 absentee ballots had been sent out, and 217,329 have been returned — meaning one-third of registered voters have already weighed in.

They did so over a bruising campaign that Democrats tried to turn into a referendum on Trump’s Washington, and that Republicans tried to turn into a referendum on Quist. The Democrat’s closing ads hammer the AHCA as a “tax cut for millionaires,” pointing out that Gianforte would be a beneficiary. In Butte, and in his other stops, Sanders called the AHCA “one of the most disgraceful, un-American pieces of legislation ever passed,” and promised that Quist would “make certain that the bill goes nowhere.”

Republicans have not mentioned the bill in campaign spots. Gianforte was also hurt in the final stretch when a recorded phone call with potential donors found him praising the AHCA’s passage in the House — although his campaign had not declared whether or not he supported the bill.

In Montana and elsewhere, Republicans see their bill’s progress as a boon for base turnout. At the House GOP conference’s Thursday meeting, Speaker Paul D. Ryan (Wis.) told members that simply casting the vote, and reviving the chance to repeal part of the Affordable Care Act, had been helpful in close races.

“Since the passage of the health care bill that we passed, you know, things are actually looking even more optimistic in some of these special races,” said Rep. Robert B. Aderholt (R-Ala.), characterizing Ryan’s pitch.

But the Gianforte strategy, a possible preview of House races to come in 2018, combined a pitch to the GOP base with a pummeling of Quist’s background. In March, the Congressional Leadership Fund (CLF) dispatched an investigator to review the musician’s tax and legal records. Private polling found that Quist was unfamiliar to 80 percent of voters but liked by those who knew him. Gianforte, who had just lost a bruising statewide race, didn’t have that luxury.

The response, splayed across local and conservative news sites — and then TV ads — was a barrage of revelations. Quist had played at a nudist colony. He’d been busted for marijuana possession in the 1970s. He’d renovated a property without reporting it on his taxes. He’d stiffed a home contractor. Nearly three-quarters of TV ads run in Montana were pro-Gianforte or anti-Quist; the closing spots from the National Republican Congressional Committee feature testimonials from people whom Quist left holding a bill.

“He started at zero, and today he’s negative 15,” said Corry Bliss, the CLF’s executive director. “If Rob Quist was running next year, if he was one of just 435 candidates, I don’t think they’d let him past the lobby of the DNC.”

In the unique circumstances of the special election, however, Republicans admit that Quist has stayed in the hunt. He has consistently — and sometimes at odds with the timeline — blamed his financial problems on a “botched surgery” that nearly wiped him out. In Butte, a labor stronghold and one of the few U.S. cities that has ever elected a Socialist mayor, Quist and Sanders shared the stage with a voter named Paula McGarvey, who told her story of cancer treatment that, in the years before the ACA was passed, drained her finances.

“First, I wiped out my savings. Next, I withdrew from my retirement account,” McGarvey said. “Not everyone has the resources I did in facing a medical crisis. If things don’t change in Washington, we all face the risk of losing our health care or going broke. It’s not healthy to send another Republican to Washington, and that’s why Rob Quist has my vote.”

In his own speech — after citing a poem about Montana’s natural beauty — Quist rounded on the AHCA.

“Public lands were my number one issue until the House passed this disastrous health care bill,” said Quist. “We should all resist the assault on women’s reproductive rights. These are more than women’s issues. These are human issues and family issues and community issues.”

Issue by issue, especially after Republicans moved on from accusing Quist of favoring a national gun registry, the Democrat was in a stronger political position than seemed possible in January. Democrats note that a May visit by Vice President Pence to support Gianforte drew just 800 people in Billings, Montana’s biggest city. Rallies with Donald Trump Jr., which focused on small-dollar fundraising, had been even smaller.

There was no talk of the president himself campaigning in Montana, but private polling has found his own numbers slipping. Trump enjoys a positive approval rating in the single digits. On the donor call that caused trouble for Gianforte, Republicans speculated that a rout would mean more danger for incumbent Sen. Jon Tester (D-Mont.), a possibility that now looks more remote.

And in Butte, Sanders quickly moved past the Russia and FBI stories that were causing Trump trouble in Washington to sell Quist as a progressive, who’d take the fight to the wealthiest. Seven months after losing the state by a landslide, Sanders argued that beating the AHCA — and winning some elections — could set up a longtime left-wing policy goal.

“We are calling on Congress to pass Medicare for All, single payer,” Sanders said. “Do not tell me that we, in the United States, cannot pass a Medicare for All system.”

Mike DeBonis contributed to this report.