In battleground Ohio, the President took credit for Republican Troy Balderson’s performance, calling it “a great victory,” even though the contest could be headed to a recount.

Two high-stakes elections that tested President Donald Mr. Trump’s clout and cost both parties millions of dollars were too close to call early on Wednesday. Mr. Trump claimed victory in one nevertheless.

In battleground Ohio, the President took credit for Republican Troy Balderson’s performance, calling it “a great victory,” even though the contest could be headed to a recount. Democrats could also celebrate their showing in a district that has gone Republican for decades.

“We’re not stopping now,” Democrat Danny O’Connor told cheering supporters. He’ll reprise his campaign against Mr. Balderson from now through November’s general election.

In deep-red Kansas’ Republican gubernatorial primary, the candidate Mr. Trump backed on the eve of the election, Secretary of State Kris Kobach, was neck and neck with current Republican Gov. Jeff Colyer.

The day’s races in five states, like many before them, tested the persistence of Mr. Trump’s fiery supporters and the momentum of the Democratic Party’s anti-Trump resistance.

The results were helping determine the political landscape and Mr. Trump’s standing within his own party as the GOP defends its House and Senate majorities this fall.

In Kansas, Republicans were fighting among themselves in an unusual battle for Governor in which the President sided with the incumbent’s challenger.

Should the polarising Kobach win the primary, some Republican operatives fear he could lose the governorship to Democrats this fall. The race could become further disrupted if Kansas City-area businessman Greg Orman makes it onto the November ballot. He submitted petitions on Monday with more than 10,000 signatures for what could become the most serious independent run for Kansas Governor in decades.

Danny O'Connor, the Franklin County recorder, speaks during an election night watch party at the Ohio Civil Service Employees Association on August 7, 2018, in Westerville, Ohio. | Photo Credit: AP

Mr. Trump made his preference clear for Mr. Kobach.

“He is a fantastic guy who loves his State and our Country — he will be a GREAT Governor and has my full & total Endorsement! Strong on Crime, Border & Military,” the President tweeted on the eve of the election.

Republicans were hoping for Democratic discord in Kansas’ 3rd Congressional District, a suburban Kansas City district where several candidates were fighting for the chance to take on Republican Rep. Kevin Yoder in November.

The five-way Democratic primary featured labour lawyer Brent Welder, who campaigned recently with self-described democratic socialists Vermont Sen. Bernie Sanders and ascending political star, Alexandria Ocasio-Cortez, a New York congressional candidate.

Also in the race — Native American attorney Sharice Davids and former school teacher Tom Niermann.

In Ohio, the script for the special election was somewhat familiar — An experienced Trump loyalist, Mr. Balderson, was fighting a strong challenge from Mr. O’Connor, a fresh-faced Democrat, in a congressional district held by the Republican Party for more than three decades. As voters were going to the polls, Mr. Trump said Mr. Balderson would make a “great congressman.”

The winner takes the seat previously held by Pat Tiberi, a nine-term incumbent who resigned to take a job with an Ohio business group.

Mr. Balderson and Mr. O’Connor will reprise their race in the general election in just three months. There were at least 3,367 provisional ballots left to be reviewed. That’s enough for Mr. O’Connor to potentially pick up enough to force a recount.

The Associated Press does not declare winners in races subject to an automatic recount.

In a special election season that featured nearly a dozen congressional contests, Democrats claimed just a handful of wins, but they may have cause for optimism this fall. In virtually every special election test dating back to the spring of 2017, Democratic candidates performed significantly better than their party in those same places two years earlier.

Mr. Trump won Ohio’s 12th Congressional District, for example, by more than 11 points in 2016; on Tuesday night, Mr. Balderson and Mr. O’Connor were separated by less than 1 point.

There are 79 House races this fall considered more competitive than the Ohio district at least looking at Mr. Trump’s 2016 performance according to data compiled by the Democrats’ national campaign committee.

Despite the deadlocked race, the specific Ohio returns suggest considerably higher Democratic enthusiasm less than 100 days before the midterms.

Mr. O’Connor’s total of nearly 100,000 votes far exceeded what the district’s former Republican congressman Pat Tiberi’s Democratic opponent got in 2014. Mr. Balderson’s total just more than 101,500 votes is barely two-thirds of Tiberi’s 2014 mark of about 150,000.

The two will face off again in November to see who holds the seat in 2019 and 2020.

“Over the next three months, I’m going to do everything I can to keep America great again, so that when we come back here in November get ready, we gotta come back here in November I have earned your vote for a second time,” Mr. Balderson told supporters.

It’s unclear how much Mr. Trump’s support helped or hurt Mr. Balderson. Described by campaign operatives as a “Whole Foods” district, the largely suburban region features a more affluent and educated voter base than the typical Mr. Trump stronghold.

Ohio Gov. John Kasich, a leading voice in the GOP’s shrinking anti-Mr. Trump wing, once represented the district in Congress.

At times, the race centered on Mr. Trump’s tax cuts as much as the candidates.

Mr. O’Connor and his Democratic allies railed against the tax plan, casting it as a giveaway for the rich that exacerbates federal deficits and threatens Medicare and Social Security. Mr. Balderson and his Republican allies have backed away from the tax plan in recent weeks, training their fire instead on top House Democrat Nancy Pelosi.

Mr. O’Connor dominated Mr. Balderson on the local airwaves. His campaign spent $2.25 million on advertising compared to Mr. Balderson’s $507,000, according to campaign tallies of ad spending. The Republican campaign arm and its allied super PAC were forced to pick up the slack, spending more than $4 million between them.

In Michigan, former state Rep. Rashida Tlaib is poised to become the first Muslim woman in Congress. She won the Democratic nomination to run unopposed in November.

And in suburban Seattle, three Democrats vied in a jungle primary for the seat held by another retiring Republican, Rep. Dave Reichert.

The field was set in two Senate contests.

In Missouri, Democratic Sen. Claire McCaskill claimed her party’s nomination, while state Attorney General Josh Hawley will represent the GOP.

And in Michigan, Democratic Sen. Debbie Stabenow will take on military veteran and business executive John James, who won the Republican nomination. He would join Tim Scott of South Carolina as the only black Republican senators if he wins in November.

Mr. Trump has tweeted that James is “a potential Republican star.”