BOZEMAN, Mont. — Republican businessman Greg Gianforte won Montana’s sole House district in a special election Thursday, keeping a seat in Republican hands despite facing assault charges for allegedly attacking a reporter who’d asked him about the GOP’s health-care bill.

In his victory speech, Gianforte admitted to the attack and apologized for it.

“I shouldn’t have treated that reporter that way,” he told supporters at his rally here.

The victory, called by the Associated Press, offered some relief for Republicans, who have struggled to sell their Obamacare overhaul, the American Health Care Act. But it was a closer call than the party had expected when it tapped the multimillionaire to run in a state President Trump carried by 20 points — and when Democrats nominated folk singer Rob Quist instead of an experienced politician. With 83 percent of the vote counted, Gianforte led Quist 51 percent to 44 percent, according to preliminary returns.

Some in the crowd laughed at the mention of the incident. “I made a mistake,” said Gianforte.

“Not in our minds!” yelled a supporter.

Democrats, who called on Gianforte to quit the race after the assault charge, believed that late votes broke Quist’s way, and that the first-time candidate put the race in play by attacking the AHCA. Forcing Republicans to spend seven figures defending a typically safe seat, they argued, was worth it.

“We said at the outset that this would be a very difficult election on very red turf,” said David Nir, the political director of Daily Kos, which endorsed Quist and crowdfunded donations for him. “The playing field next month in Georgia and next year in the midterms is much more favorable. Republicans might be breathing a sigh of relief that their morally reprehensible candidate won on Thursday night, but they should still be very worried about 2018.”

Quist conceded defeat shortly after 11 pm local time. “Your voices were definitely heard in this election,” he told supporters at his election party in Missoula. “I know we came up short but the energy and the grassroots movement in this state goes on.”

In-person voting began across the state just hours after Gianforte allegedly “body-slammed” Guardian reporter Ben Jacobs, who was trying to ask him a question about the House Republican health-care plan. Gianforte has been charged with misdemeanor assault.

“I’m glad I waited to vote until today,” Wolf Redboy, 43, a software marketer and musician from Missoula, who backed Quist, said Thursday. It was the first election he’d voted in since 2012. “I couldn’t believe what I was hearing in that tape. There are lots of words that come to mind for people who want to treat reporters that way.”

The scuffle was caught on tape by the reporter and witnessed by a Fox News reporting team. Gallatin County police announced the charges late Wednesday after the Guardian published the recording.

On Thursday, as three major newspapers pulled their endorsements of the technology entrepreneur and some early voters sought in vain to change their ballots, GOP leaders urged Gianforte to apologize in an attempt to control the damage.

“There is no time where a physical altercation should occur,” House Speaker Paul D. Ryan (R-Wis.) said at his weekly news conference on Capitol Hill. “It should not have happened. Should the gentleman apologize? Yeah, I think he should apologize.”

Sen. Steve Daines (R-Mont.), one of Gianforte’s closest allies in Montana politics and a former co-worker at his Bozeman company, called his actions “unacceptable” and agreed that he should apologize. Quist, meanwhile, told reporters Thursday that the scuffle was a “matter for law enforcement” and declined to comment further.

Wednesday’s incident took place after nearly four weeks of voting in a special election to replace Ryan Zinke (R), who became Trump’s interior secretary in March. By Thursday, more than 200,000 of 700,000 eligible voters had cast early absentee ballots.

In interviews at Quist’s final rally, at a Missoula microbrewery, voters were skeptical that the attack could change the race. Gianforte entered the contest with high negative ratings and an image as a hard-charging bully who had joked about outnumbering a reporter at a town hall meeting and sued to keep people from fishing on public land near his home.

“Greg thinks he’s Donald Trump,” said Brent Morrow, 60. “He thinks he could shoot a guy on Fifth Avenue and get away with it.”

Gianforte and the allied super PACs had deflected attention from his low approval numbers with ads attacking Quist over unpaid taxes and gaffes about gun rights and military spending. To the extent the assault charge hurt — a GOP-aligned poll found 93 percent of voters aware of it — Republicans thought it denied them another day of attention on Quist.

For 24 hours, the assault charge was the biggest political story in Montana. The Billings Gazette, which serves Montana’s largest city, told readers that it had made a “poor choice” by ignoring “questionable interactions” the candidate has had with reporters in the past. Two other major newspapers also pulled their Gianforte endorsements, with the Missoulian suggesting that the Republican should bow out of public life.

As word spread of the alleged assault in Bozeman, some supporters who had been knocking on doors for Quist began playing voters the audio clip. The Democratic Congressional Campaign Committee, which has invested more than $500,000 in the race, called for Gianforte to quit the race and released a last-minute radio ad featuring Jacobs’s audio of the incident.

In the recording, Jacobs could be heard asking Gianforte to respond to the newly released Congressional Budget Office score of House Republicans’ AHCA, a bill Gianforte had said he was glad to see the House approve.

After Gianforte told Jacobs to direct the question to his spokesman, there was the sound of an altercation, and a screaming candidate.

“I’m sick and tired of you guys!” Gianforte said. “The last guy that came in here did the same thing. Get the hell out of here! Get the hell out of here! The last guy did the same thing. Are you with the Guardian?”

Quist surprised both parties by running — and by securing the Democratic nomination. A supporter of Bernie Sanders’s 2016 presidential bid, he told activists he backed Canadian-style single-payer health care, and he waxed to local reporters about whether taxes should be raised on the rich, whether military spending should be slashed and whether assault weapon owners should register their guns.

In the first months of the race, Quist raised just $900,000 and appeared to be written off by Washington Democrats. Republicans attempted to define the candidate before he could go on the air, with the opposition research group America Rising paying a tracker to follow Quist, and the Congressional Leadership Fund super PAC hiring a researcher to dig up damaging stories about the musician-turned-politician’s tax problems. More than $5 million was spent by outside groups against Quist; Democrats responded with less than $1 million in positive spots.

“We knew that because Rob Quist was an unknown quantity with voters, we had the ability to define him negatively out of the gates,” said America Rising chief executive Colin Reed.

But after the March failure of the first version of the AHCA, Quist’s fundraising surged, adding up to more than $5 million by the final pre-election report — outmatching Gianforte, whom Republicans had hoped would self-fund his campaign.

The AHCA, the Republican replacement for the Affordable Care Act, had become the dominant issue in the campaign. In the closing days of the race, Quist focused his events and TV ads on his opposition to the Republican bill and brought in Sanders (I-Vt.) to help promote his position on U.S. health care: universal coverage.

The Republican struggled to talk about the AHCA. In public, he said that he would wait to weigh in on the legislation until the CBO score was released and assured him that protections for people with preexisting medical conditions wouldn’t be scrapped. On a call with donors that was leaked to newspapers including The Washington Post, the Republican said he was “thankful” for the House’s vote that moved the bill forward.

At campaign stops and on TV, the soft-spoken Quist either rebutted Republican attack ads or attacked the GOP’s health-care bill, hitting Gianforte especially hard on the donor call remarks.

“Greg Gianforte says he’s thankful for the new health-care bill, the one that eliminates protections for preexisting conditions and raises premiums on every Montanan who has one, because he gets a big tax break at our expense,” Quist said in his closing spot.

Until Wednesday, Democrats worried that a loss would bolster Republican confidence to move ahead with the health care bill. But Gianforte’s triumph over the assault charges gave the winners another reason to cheer — a victory over what the president calls “fake news.”

At Gianforte’s party in Bozeman, Rehberg — among other revelers — spread a shaky rumor that the Fox News journalists who spoke to police were “changing their story.”

In Missoula, where Quist rallied with his voters, Democrats looked for the bright side. Matt McKenna, an adviser to the campaign and a longtime Montana politics insider, noted the ugly tenor of the race, starting with anti-Quist ads the first day of the campaign.

“This is the first day of the end of Greg Gianforte’s political career,” said McKenna. “It may seem like he got away with this because so many people already voted, but they will deny him the prize he really wants which is the governor’s office. He could go to jail. He still has to be arraigned.”

Viebeck reported from Washington. Kathleen McLaughlin in Missoula, Mont., and Ed O’Keefe and Sean Sullivan in Washington contributed to this report.