In this Aug. 4 photo, Ohio state Sen. Troy Balderson (R) clasps hands with President Trump as Balderson speaks during a rally at Olentangy Orange High School in Lewis Center, Ohio. Balderson on Friday was named the winner of the Aug. 7 special election for a House seat long held by Republicans. (Carolyn Kaster/AP)

Republican Troy Balderson was declared the winner Friday of a closely contested special House election in central Ohio, 17 days after voting took place in a district Republicans have held for decades.

After thousands of provisional and absentee ballots were counted, Balderson, a state senator, had defeated Democrat Danny O’Connor. Balderson prevailed in the Aug. 7 contest by 0.8 percentage points; a margin under 0.5 points would have trigged a recount.

“I’m humbled by the support I’ve received from voters and look forward to representing Ohio’s 12th Congressional district in Congress,” Balderson said in a statement Friday. He added that O’Connor ran a “hard-fought race” to finish the term of Rep. Patrick J. Tiberi (R-Ohio), who retired in January.

Balderson and O’Connor will face off again Nov. 6, competing this time for a full two-year term in Congress.

Balderson’s narrow victory came in a district that President Trump won by 11 percentage points in 2016 and that the GOP has held since 1983. Balderson received the endorsements of both Trump and Ohio’s Republican Gov. John Kasich.

O’Connor ran a closer race than Republicans expected. Balderson, who also had been endorsed by Tiberi, was seen as the most electable and business-friendly candidate in a crowded field. O’Connor, the young clerk of Franklin County, did not have the additional heft of the military background that helped Rep. Conor Lamb (D-Pa.) prevail in a closely watched special election this year.

Republicans nonetheless had to scramble to hold the seat. Vice President Pence made two trips to the district, while House Speaker Paul D. Ryan (R-Wis.) and President Trump both made high-profile campaign stops. The Congressional Leadership Fund, a Ryan-allied PAC, spent $2.7 million on TV ads against O’Connor.

“This special general election race never should have been this close,” conservative Club for Growth president David McIntosh wrote in a column this week. “Republican and independent voters are sending a message — they are rejecting establishment orthodoxy — that it is not okay to run as a conservative and govern as a moderate.”

In a statement, O’Connor said that he would keep campaigning across the district to “give working people a tax cut and protect Social Security and Medicare,” carrying on the message from the special election.

“We have eleven weeks to keep talking to voters, listening to their ideas and to bring home a win for working families in Central Ohio,” O’Connor said.

In defeat, Democrats argued that the special election gave them a blueprint to use in other races.

Turnout had been highest in O’Connor’s Franklin County, which covers the city of Columbus and its suburbs, and which gave the Democrat nearly two-thirds of the vote. It had sagged in rural areas, despite the president’s in-person appeal to his political base.

“The reason this got so close was because of turnout,” said Ohio Democratic Party chairman David Pepper. “We’re turning out our voters, and the other guys don’t know what their message is.”