Media playback is unsupported on your device Media caption Democrat Andy Beshear claims victory in Kentucky's tight governor race

US Democrats have made gains in state elections, in what is being seen as a blow to President Donald Trump.

Democrat Andy Beshear claimed victory in Kentucky's governor vote, after a tight race in the conservative-leaning state.

Meanwhile, Democrats seized full control of the legislature in Virginia for the first time in over 20 years.

The results are a gauge of the political mood ahead of next year's presidential election.

Republicans held on to power in the Mississippi governor vote, following a closely-fought race in the traditional Republican stronghold.

US state governors head the executive branch in state governments.

In Kentucky, Mr Beshear claimed victory over incumbent Republican governor Matt Bevin after final results gave him a lead of 0.4%.

Mr Bevin, 52, says he will not concede, citing unspecified "irregularities".

However, Mr Beshear, a 41-year-old attorney general whose father is a former governor of the state, said: "We will be ready for that first day in office and I look forward to it."

The loss will be seen as a setback for Mr Trump, who attempted to galvanise support for Mr Bevin at a campaign rally in Kentucky on Monday night.

In a speech to thousands of supporters, Mr Trump said a loss for Mr Bevin would be characterised as "the greatest defeat in the history of the world" by his critics.

Mr Beshear, he said, was "too extreme and too dangerous" to govern the state.

However, polls showed Mr Bevin was one of the least popular governors in the country, following high-profile battles with unions and teachers.

Image copyright Getty Images Image caption Matt Bevin was elected governor of Kentucky in 2015

Despite losing the governor's race, Republican candidates claimed victory in five other votes in Kentucky, including a poll for the state's attorney general, won by Daniel Cameron. Mr Cameron will be the first African-American attorney general in Kentucky's history, and the first Republican to do so in more than 70 years.

The southern state voted overwhelmingly for Donald Trump in the 2016 presidential race, giving him a nearly 30% margin over Hillary Clinton - the highest winning margin of any Republican presidential candidate in Kentucky in over 40 years.

In Pennsylvania, for the fist time since the American Civil War, Democrats took control of the five-member council in Delaware County, just outside Philadelphia.

Meanwhile, in Virginia, the Democrats overturned Republican majorities in both chambers of the state legislature.

The elections of Danica Roem, the first openly transgender person to serve in the House, and Ghazala Hashmi, who will be the first Muslim woman in the Senate, were among the Democrats' notable victories in the state.

Virginia also saw Juli Briskman - who gained US media attention in 2017 after she lost her job for making an obscene gesture at Mr Trump's motorcade - elected as a district representative in Loudoun County.

Ahead of the vote, Democratic presidential hopefuls - including frontrunners Joe Biden and Elizabeth Warren - had campaigned with local candidates.

With full control of the state legislature, Virginia Democrats are expected to push for tighter gun-control, health insurance reform and other policies opposed by Republicans.

Virginia's blue wave also marks a remarkable turnabout in political fortunes for Democratic Governor Ralph Northam.

He was beset by demands to quit back in February after admitting he had worn blackface while in medical school in the 1980s.

On Tuesday, Mr Northam said the election results showed Virginia's voters "want us to defend the rights of women, LGBTQ Virginians, immigrant communities, and communities of colour".

The Democrats benefited from massive spending by former New York Mayor Michael Bloomberg. The billionaire's gun control advocacy group Everytown for Gun Safety pumped $2.5m (£1.94) into the state's race, far outspending the $300,000 from the National Rifle Association (NRA) - the formidable US gun lobby, which is based in Virginia.

Everytown focused advertisements in suburban swing districts, targeting Republican incumbents and pushing to make gun control a key issue at the ballot box.

In July, one month after a mass shooting in Virginia Beach killed 12 people, the state's Republicans abruptly ended a special legislative session focused on gun control after 90 minutes - without considering a single bill.

Kentucky suburbs defy Trump

Anthony Zurcher, BBC's North America correspondent

Republican Matt Bevin was a Donald Trump-style candidate a year before Donald Trump won the presidency.

Once in office, Bevin governed a lot like Trump, as well. Despite sinking popularity in opinion polls, he contended that he would win comfortable re-election.

He didn't. Bevin's strength in the rural parts of the state weren't enough to overcome Beshear's margins in the cities and - of particular concern to Republicans - the kind of suburban areas that also were key to many Democratic wins in 2018.

Trump himself threw his support behind Bevin in the campaign's closing days, holding a rally in Lexington on Monday and warning that a Bevin loss could bolster the forces pushing for his impeachment.

Republicans did well in other Kentucky races and Bevin's loss may be by the narrowest of margins, but it will be cited as evidence of Trump's weakened political muscle.

Although the presidential election is a year away, Tuesday's results are being touted as a reflection of Mr Trump's popularity among voters as he faces an impeachment inquiry.

Reacting to the results on Twitter, Mr Trump hailed the performance of Republicans in Kentucky and Mississippi.

He congratulated Tate Reeves, who defeated Democrat Jim Hood to extend the Republican Party's two-decade hold on the governor's office in Mississippi.

On Mr Bevin's defeat, Mr Trump's 2020 campaign manager suggested the president's presence at a rally in the state boosted his vote-share.

"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," Brad Parscale said.