(Reuters) - U.S. Democrats claimed an upset win in Kentucky on Tuesday over a Republican governor backed by President Donald Trump and seized control of the state legislature in Virginia, where anti-Trump sentiment in the suburbs remained a potent force.

The outcomes of Tuesday’s elections in four states, including Mississippi and New Jersey, could offer clues to how next year’s presidential election could unfold, when Trump will aim for a second four-year term.

In Kentucky, Democratic Attorney General Andy Beshear, whose father, Steve, was the state’s last Democratic governor, scored a narrow victory over Governor Matt Bevin despite an election-eve rally headlined by Trump.

In a speech in Lexington, Kentucky, on Monday night, Trump - who won Kentucky by 30 percentage points in 2016 - told voters that they needed to re-elect Bevin, or else pundits would say the president “suffered the greatest defeat in the history of the world.”

The remarks reflected the extent to which Bevin, 52, sought to nationalize the campaign, emphasizing his support for Trump amid a Democratic-led impeachment inquiry of the Republican president in Congress.

While the result was a significant setback for Trump, who remains relatively popular in Kentucky, it may have had more to do with Bevin’s diminished standing in the state. Opinion polls showed Bevin may be the least popular governor in the country, after he waged high-profile fights with labor unions and teachers.

Beshear’s upset win could also bolster Democrats’ slim hopes of ousting Republican Senate Majority Leader Mitch McConnell, who is on the ballot himself in the state next year.

At a rally on Tuesday night, Bevin refused to concede, citing unspecified “irregularities,” even as Beshear called on the governor to honor the results.

Trump asserted on Twitter that his rally had helped Bevin avoid a bigger loss and boasted that Republicans had won several other statewide races.

Slideshow ( 15 images )

“@MattBevin picked up at least 15 points in last days, but perhaps not enough (Fake News will blame Trump!),” the president wrote.

Meanwhile, Democrats wrested both chambers of Virginia’s legislature from narrow Republican majorities, which would give the party complete control of the state government for the first time in a quarter-century.

Trump has avoided Virginia, where Democrats found success in suburban swing districts in last year’s congressional elections, as they did in states across the country. Tuesday’s election, which saw Democrats prevail in several northern Virginia suburbs, suggested the trend was continuing.

In Mississippi, where Republican Governor Phil Bryant was barred from running again due to term limits, Republican Lieutenant Governor Tate Reeves defeated Attorney General Jim Hood, a moderate Democrat who favors gun rights and opposes abortion rights.

Like Bevin, Reeves campaigned as a staunch Trump supporter in a state that Trump easily won in 2016. The president held a campaign rally in the state last week alongside Reeves.

In New Jersey, Democrats were expected to maintain their majority in the state’s general assembly, the legislature’s lower chamber.

VIRGINIA IN THE SPOTLIGHT

The Virginia contest drew heavy attention and money from both parties. Former Vice President Joe Biden, a Democratic presidential front-runner, visited Virginia over the weekend to campaign with several statehouse candidates, and Republican Vice President Mike Pence held a rally on Saturday.

Slideshow ( 15 images )

Other Democratic presidential contenders, including U.S. Senators Elizabeth Warren, Kamala Harris, Amy Klobuchar and Cory Booker, have also campaigned with local candidates.

In one notable race, Democrat Shelly Simonds, who lost a state House of Delegates race in 2017 via random draw after the election ended in a tie, won a rematch against Republican David Yancey.

Virginia’s Democratic gains came despite a year of scandal for the party’s top officials in the state. Governor Ralph Northam barely endured a political firestorm after his yearbook page was shown to have photos of someone in blackface and another person in a Ku Klux Klan costume, while Attorney General Mark Herring admitted to wearing blackface himself in college.

Lieutenant Governor Justin Fairfax, meanwhile, has denied two accusations of sexual assault.

The legislative wins likely mean that Democrats can pass a raft of bills that Republicans had resisted, including new gun limits. Democrats will also control the redistricting process in 2021, when lawmakers draw new voting lines for state and congressional elections after next year’s U.S. Census.