Washington (AFP) - Democrats celebrated Wednesday after marquee election wins in two US states -- including an upset in a Republican stronghold -- seen as tests of President Donald Trump's political standing ahead of the 2020 elections.

In a sign of trouble for Trump, Democratic challenger Andy Beshear claimed a narrow victory in Kentucky's gubernatorial race over Republican incumbent Matt Bevin, who has refused to concede.

Doubling the hurt, Democrats gained control of both chambers of the legislature in Virginia for the first time in 25 years, flipping a formerly red state solid blue and signaling the growing importance of suburban voters who have turned decisively against Trump.

Trump put on a brave face over the Kentucky results, insisting it was overall good news because Republicans won races down the ballot.

"A lot of winning in Kentucky. Check out the numbers," he said, indicating he believed that his election-eve rally in Lexington helped bring Bevin, who was trailing in polls, to within 0.4 percent of Beshear in the governor results.

Bevin did not throw in the towel, and wrote to Kentucky's secretary of state formally seeking a "recanvass" of voting machines and absentee ballots, which will be conducted on November 14.

Should Bevin's loss be certified, it would be a shock defeat for a conservative in a southern state that Trump won by 30 percentage points in 2016.

It does not mean Kentucky would be in play in next year's presidential election. Bevin had become a deeply unpopular governor and the results showed.

The chance of Kentucky voting against Trump in 2020 is remote, but the results raise the alarm that he faces deep discontent even on friendly turf.

Despite the Republican embarrassment in Kentucky and Virginia, the party held fast to a governorship in traditionally conservative Mississippi.

Republican Tate Reeves won the governor's race there by a comfortable margin against Jim Hood, an anti-abortion, pro-gun Democrat.

Story continues

Trump had campaigned in both Mississippi and Kentucky in the closing days of the race. But he stayed away from Virginia, which has been steadily shifting blue over the past decade, and where Republicans had distanced themselves from him.

Democratic leadership swiftly portrayed the night as a massive boost for the party heading into next year's monumental battle against the president.

"This historic victory should send a chill down the spines of Donald Trump and every Republican," Democratic National Committee chairman Tom Perez said in a statement.

- 'Finish the job' -

"Democrats are competing in every election and every state, running on our values, and channeling unprecedented energy into the voting booth... That's how we'll beat Trump."

Tuesday's elections were tests of enthusiasm ahead of 2020 for Trump, who is deeply unpopular nationwide and is the subject of an impeachment investigation.

With Washington swept up in the impeachment saga, election results were closely watched for how the crisis is playing out with voters.

The Kentucky result -- boosted by strong Democratic turnout in suburban districts outside Lexington and other major cities -- is all the more humiliating for Trump because he flew there Monday night to hold a large rally and implore his base to come out to the polls.

"If you lose, it sends a really bad message," he said. "You can't let that happen to me."

Also on that night, he blasted Democrats for voting to bring the impeachment probe to a new, public phase.

"The Democrats' outrageous conduct has created an angry majority that will vote the do-nothing Democrats the hell out of office," Trump said.

Instead, the opposite happened.

"Last night voters across the country made clear: they're tired of a government that works for the 1% while working people suffer. They want real change," said liberal Senator Bernie Sanders, who is running for the 2020 Democratic presidential nomination.

"Next year we'll finish the job" and sweep Trump from the White House, Sanders said.

Democrats say they have been able to flip seats blue because many voters have soured on Trump and his divisive policies and rhetoric.

"In particular, Democrats' successes on Tuesday... were driven by their remarkably strong performances in suburban areas," analysts Nathaniel Rakich and Geoffrey Skelley wrote on FiveThirtyEight.com.