Kentucky Attorney General Andy Beshear is the apparent winner over Republican Gov. Matt Bevin, a huge upset and a blow to President Donald Trump, NBC News projects.

Trump had endorsed Bevin and campaigned with him in Lexington the night before the election, where the president told supporters that a loss by the GOP governor would be portrayed as Trump's having suffered "the greatest defeat in the history of the world."

The candidates were separated by less than 10,000 votes, with 99 percent of precincts reporting. Beshear was leading with 49.4 percent, or 706,865 votes, to Bevin's 48.7 percent, or 696,918 votes.

Turnout appeared to be higher than expected and is estimated at 1.4 million — roughly 400,000 more than the last governor's contest in 2015, according to an NBC News analysis.

Trump injected himself into the race, traveling to Lexington on Monday to boost Bevin's re-election campaign.

Read the full story at NBC NEWS.