Republicans appear to have narrowly held off a Democratic surge in a traditionally conservative Ohio district many Democrats had hoped would serve up an unlikely victory and boost their chances of sweeping wins in November’s midterm elections.

With a margin of 50.2% to 49.3%, the Republican Troy Balderson was just ahead of the Democrat Danny O’Connor on Tuesday night in a congressional special election that has tested Donald Trump’s clout and cost both parties millions of dollars.

While Democrats will be disappointed that they were not able to claim an outright victory, the tight margin will still be a reason for optimism ahead of November’s midterm elections.

Republicans declared victory with Steve Stivers, the head of the National Republican Congressional Committee, saying: “I’m proud that my fellow central Ohioan, Troy Balderson, will join me in Congress” and congratulating him on a “hard-fought victory”.

But O’Connor has not conceded, telling a crowd of supporters: “Can you believe how close this is? We are in a tie ballgame.”

American democracy is in crisis, and not just because of Trump | Simon Tisdall Read more

With all votes counted, Balderson had a lead of 1,754 votes. However, according to the Ohio secretary of state, there remained 3,435 provisional ballots to be counted and 5,045 outstanding absentee ballots. If, after those are counted, the margin is within 0.5%, an automatic recount would be triggered.

The race had been closely watched as a key test of Republican fortunes in prosperous traditionally conservative suburbs where voters have soured on Trump. However, while Balderson’s performance was far weaker than past Republicans in the district, he held on to just enough suburban Republicans to hold a narrow lead on election night.

But Republicans were only able to win a once safe district by spending millions in outside money and an election eve visit from Trump. In November, Republicans will be defending over 70 seats that are considered more favorable for Democrats and will not have those advantages.

The national mood wasn’t the only impediment for Balderson. The Ohio Republican had been considered by operatives to be an underwhelming candidate. He was a lackluster fundraiser and avoided the press even to point of shunning friendly outlets like Fox News. Even in voter interactions, Balderson left much to be desired. Appearing at a polling place on election day, the Republican candidate milled around a parking lot for several minutes, waving and saying hello to passersby without making any attempt to ask for their votes.

Facebook Twitter Pinterest The Democrat challenger Danny O’Connor. Photograph: John Minchillo/AP

Balderson also had several stumbles. He went back and forth about how much to separate himself from Trump. This was a particularly thorny issue in the home district of John Kasich, the popular Republican governor of the state who has remained an unabashed critic of Trump. At one point in the campaign, Balderson couldn’t name a single area of disagreement but has since cited differences on tariffs and immigration. Those mild criticisms were sufficient to earn him a belated endorsement from Kasich.

That endorsement might have helped to push Balderson over the edge. In Delaware County, a suburban Republican stronghold that has been Kasich’s base, several voters told the Guardian they supported Balderson despite feeling uneasy about Trump and cited Ohio’s governor in doing so. O’Connor ended up winning 46% of the vote there, seven points ahead of Hillary Clinton in 2016 and a significant landmark in a county that no Democratic presidential candidate has won in 100 years.

However Trump, who held a rally for Balderson on Saturday, took credit for the result on Twitter: “When I decided to go to Ohio for Troy Balderson, he was down in early voting 64 to 36. That was not good. After my speech on Saturday night, there was a big turn for the better. Now Troy wins a great victory during a very tough time of the year for voting. He will win BIG in Nov.”

Balderson made a prominent gaffe on election eve, telling voters in his rural home town of Zanesville: “We don’t want somebody from Franklin County representing us.” Franklin County makes up roughly a third of the district. When asked about this in the polling place parking lot by the Guardian, Balderson turned his back and left it to an accompanying aide to insist that Balderson really meant O’Connor was a liberal.

The Ohio Republican was buoyed by a tsunami of outside money. The Conservative Leadership Fund, a Super Pac allied with Paul Ryan, spent more than $2.7m on television advertising alone and sent staffers to knock on more than 500,000 doors in the district.

In contrast, O’Connor ran a textbook campaign for a Democrat in such a conservative district. He insisted he would not support Nancy Pelosi for speaker and his talking points focused on defending social security and Medicare and criticizing the corporate components of the 2017 Republican tax cut bill. However, he suffered one setback when he said he would support Pelosi over a Republican in a television interview. “I will support whoever the Democratic party puts forward,” said O’Connor in a statement that Balderson and his outside allies immediately pounced on.

The close result though was celebrated as a victory by many at O’Connor’s election night party. David Pepper, the chairman of the Ohio Democratic party, was buoyed by the result. “We were underdogs from the start. The idea that we kept it this close, if Republicans aren’t worried about that they are making a mistake.”