Republicans held onto Montana's only seat in the U.S. House of Representatives Thursday night, even after GOP nominee Greg Gianforte was cited for misdemeanor assault against a reporter hours before the polls opened.

Rob Quist, a Democrat from the Bernie Sanders wing of the party, proved a prodigious fundraiser by collecting nearly $7 million from the left-wing grassroots. But it wasn't enough for the cowboy hat-wearing folksinger to prevail in a state President Trump won handily last year.

The race was called shortly after midnight. By Friday morning, with nearly 100 percent of the vote in, Gianforte had 50.2 percent of the vote, Quist, had 44.1 percent, and Libertarian Mark Wicks has 5.7 percent.

It's a big comeback for Gianforte, who lost a bid for governor of Montana last year, but an even bigger victory for national Republicans trying to stave off perceptions that Trump is leading the party over a cliff ahead of the 2018 midterm elections.

The race is important because it is one of several special elections in Republican-leaning districts that preview how much ground the GOP will be forced to defend next year. So far, Republicans have underperformed in these contests but they have yet to lose to the Democrats.

Each time Democrats even get close to an upset, however, it helps them raise money and recruit candidates in other, potentially more winnable races. Republicans hold a 24-seat majority in the House, including 23 districts won by Hillary Clinton in 2016.

Yet Democrats will have to wait to put a win on the board, and this is a particularly bitter pill to swallow, given Gianforte's flaws as a candidate.

The night before the election, the Republican was accused of body-slamming Guardian reporter Ben Jacobs in response to a question about the Congressional Budget Office's score of the GOP healthcare bill. Gianforte's campaign blamed "aggressive behavior from a liberal journalist" who shoved a recorder in the candidate's face.

But audio posted by Jacobs and eyewitness testimony from a Fox News crew ready to tape an interview with Gianforte suggested the response was violent and disproportionate. The president's critics in both parties argued that Trump's hostile rhetoric about the news media created a climate that made these actions more likely.

National Republicans were unhappy with Gianforte's behavior, but few were willing to concede the congressional seat. House Speaker Paul Ryan, R-Wis., urged him to apologize but also said his fitness for Congress was up to the voters in Montana to decide.

"I do not think this is acceptable behavior," Ryan said. "But the choice will be made by the people of Montana." Gianforte apologized to Jacobs in his victory speech.

The incident cost Gianforte several newspaper endorsements, but it happened late enough that it didn't hurt him at the ballot box. More than a third of the vote was cast before the incident happened.

"This race would have been over two months ago in a conventional year, where you had all 435 seats in play," Sen. Steve Daines, R-Mont., a close friend and supporter of Gianforte, told the Washington Examiner this week.

The House seat became vacant when Republican Ryan Zinke resigned to become secretary of the interior under Trump. Democrats hold the Montana governorship and one of the two U.S. Senate seats, but it is a generally Republican-leaning state.

Democrats will still be pleased that they have once again done better than normal in an unfriendly district. Republicans will rejoice in the fact that the anti-Trump "resistance" has yet to win one of these races.