LOUISVILLE, Ky. (AP) — Kentucky’s bitter race for governor went into overtime as Democrat Andy Beshear declared victory while Republican Gov. Matt Bevin, a close ally of President Donald Trump, refused to concede with results showing he trailed by a few thousand votes.

Kentucky has some sorting out to do before inaugurating its next governor.

With 100% of precincts reporting, Beshear — the state’s attorney general and the son of Kentucky’s last Democratic governor, Steve Beshear — had a lead of 5,333 votes out of more than 1.4 million counted, or a margin of less than 0.4 percentage points. The Associated Press has not declared a winner.

In competing speeches late Tuesday, Beshear claimed victory while Bevin refused to concede.

“My expectation is that he (Bevin) will honor the election that was held tonight,” Beshear said. “That he will help us make this transition. And I’ll tell you what, we will be ready for that first day in office, and I look forward to it.”

That first day isn’t far off. Kentucky inaugurates its governors in the December following an election.

Bevin, meanwhile, called the contest a “close, close race” and said he wasn’t conceding “by any stretch.”

“We want the process to be followed, and there is a process,” he said.

Bevin hinted there might be “irregularities” to look into but didn’t offer specifics. His campaign didn’t immediately respond to an email seeking an explanation.

There is no mandatory recount law in Kentucky. Bevin may request counties recanvass their results, which is not a recount, but rather a check of the vote count to ensure the results were added correctly. Bevin would need to seek and win a court’s approval for a recount.

The final hours of campaigning were dominated by the endorsement Bevin received from Trump at a boisterous rally Monday night in Lexington, Kentucky. Through a spokesman, the president boasted Tuesday night about the boost he had given the incumbent governor despite Bevin finishing with fewer votes to his name.

“The president just about dragged Gov. Matt Bevin across the finish line, helping him run stronger than expected in what turned into a very close race at the end,” Trump campaign manager Brad Parscale said in a statement. “A final outcome remains to be seen.”

Trump had loomed large in the race as Bevin stressed his alliance with the Republican president in TV ads, tweets and speeches. Trump carried Kentucky by a landslide in winning the presidency in 2016 and remains popular in the state. The president took center stage in the campaign with his election eve rally to energize his supporters to head to the polls for his fellow Republican.

But the combative Bevin had been struggling to overcome a series of self-inflicted wounds, highlighted by a running feud with teachers who opposed his efforts to revamp the state’s woefully underfunded public pension systems.

Bevin lagged well behind the vote totals for the rest of the GOP slate for statewide offices. Republican candidates swept Kentucky’s races for attorney general, secretary of state, auditor, treasurer and agriculture commissioner.

Trump took credit on Wednesday for the near sweep, tweeting, “Our big Kentucky Rally on Monday night had a massive impact on all of the races,” and claiming that Bevin “picked up at least 15 points in last days, but perhaps not enough (Fake News will blame Trump!).”

Meanwhile, the Libertarian candidate for governor, John Hicks, got 2% of the vote.

Beshear dominated in the state’s urban areas in Louisville and Lexington and won some traditionally Republican suburban counties in the state’s northernmost tip, just south of Cincinnati, to offset Bevin’s strength in rural areas. Beshear also made inroads in eastern Kentucky, winning several counties in a region where Trump is highly popular.

While Beshear looks to quickly pivot to governing, he’ll be confronted by a dominant GOP. Republicans hold overwhelming majorities in the state legislature.

Beshear maintained his focus throughout the race on “kitchen table” issues like health care and education to blunt Bevin’s efforts to hitch himself to Trump and nationalize the race.

On health care, Beshear could have an immediate impact by backing away from a Bevin proposal to attach work requirements to Medicaid benefits received under the Affordable Care Act. Bevin’s plan for some “able-bodied” recipients has been challenged in court and is yet to be enacted, and Beshear has vowed to rescind it.

On the campaign trail, Beshear also said he wants to legalize casino gambling, proposing to use that revenue to support public pensions. Some Republican lawmakers campaigning for Bevin vowed to reject that idea if it came before them.

Beshear also exploited Bevin’s feud with teachers over pensions and education issues, repeatedly referring to Bevin as a bully.

Beshear said Tuesday night that teachers shared in his victory.

“To our educators, your courage to stand up and fight against all the bullying and name calling helped galvanize our entire state,” Beshear said.

Beshear proposed a $2,000 across-the-board pay raise for public school teachers and vowed to submit “an education-first budget” to lawmakers.

School bus driver Conley McCracken said earlier Tuesday in Bowling Green that he voted for Bevin the first time. He said school issues turned him away from the Republican.

“He’s trying to keep retirement away from a lot of the teachers and school employees and things of that nature,” the 68-year-old McCracken said.

Trump’s support of Bevin wasn’t enough to get McCracken’s vote a second time around.

“I don’t like the way he’s doing (things), so I changed my mind,” McCracken said.

Jonathan Mattise contributed to this article from Bowling Green, Kentucky.