Democrat Ralph Northam has defeated Republican Ed Gillespie to become Virginia’s next governor, a potential bellwether win for Democrats ahead of midterm elections.

Since Donald Trump won the presidency, multiple elections have attracted national attention as possible referendums on the unpopular President’s performance. Democratic candidates had so far lost a pair of special elections for Congress.

The party broke through with Mr Northam’s win, and it was a significant one: Virginia has become more competitive as its changing demographics have shifted its politics to the left, and the gubernatorial race came to embody larger trends coursing through American politics. Former President Barack Obama won Virginia in 2008, the first time a Democrat had carried the state in decades - but it has remained in the Democratic column in each subsequent election.

The race pitted Mr Murphy, the state's lieutenant governor who has served under Democrat and party insider Gov Terry McAuliffe, against the former Republican National Committee chair in Mr Gillespie. Mr Gillespie aligned himself with Mr Trump and the President’s immigration hardline, releasing ads that denounced Mr Northam’s immigration record by seeking to tie him to the MS-13 gang, which Mr Trump frequently invokes to justify tougher immigration rules.

The President has regularly mentioned the race to his millions of Twitter followers, lauding Mr Gillespie and excoriating Mr Northam as weak on crime and immigration. After Mr Gillespie's loss came into focus Mr Trump swiftly moved to distance himself, writing on Twitter that the Republican “did not embrace me or what I stand for” and boasting that “we will continue to win, even bigger than before”!

For his part, Mr Northam made a concerted effort to link Mr Gillespie to Mr Trump, hoping to channel frustration with Mr Trump into electoral momentum.

That mirrored an overarching strategy for Democrats who are looking ahead to midterm elections in which they hope to claim the majority in one or both houses of Congress - a crucial means to blunt Mr Trump's agenda and a potential route to pursuing his impeachment, a stated goal of some Democratic members of Congress.

Violence on the streets of Charlottesville Show all 9 1 /9 Violence on the streets of Charlottesville Violence on the streets of Charlottesville Protesters clash and several are injured White nationalist demonstrators clash with counter demonstrators at the entrance to Lee Park in Charlottesville, Virginia. A state of emergency is declared, August 12 2017 Violence on the streets of Charlottesville Trump supporters at the protest A white nationalist demonstrator walks into Lee Park in Charlottesville, Va., Saturday, Aug. 12, 2017. Hundreds of people chanted, threw punches, hurled water bottles and unleashed chemical sprays on each other Saturday after violence erupted at a white nationalist rally in Virginia. AP Photo Violence on the streets of Charlottesville State police stand ready in riot gear Virginia State Police cordon off an area around the site where a car ran into a group of protesters after a white nationalist rally in Charlottesville, Virginia AP Photo Violence on the streets of Charlottesville Militia armed with assault rifles White nationalists, neo-Nazis and members of the 'alt-right' with body armor and combat weapons evacuate comrades who were pepper sprayed after the 'Unite the Right' rally was declared a unlawful gathering by Virginia State Police. Militia members marched through the city earlier in the day, armed with assault rifles. Getty Images Violence on the streets of Charlottesville Statue of Confederate General Robert E Lee The statue of Confederate General Robert E. Lee stands behind a crowd of hundreds of white nationalists, neo-Nazis and members of the 'alt-right' during the 'Unite the Right' rally 12 August 2017 in Charlottesville, Virginia. They are protesting the removal of the statue from Emancipation Park in the city. Getty Images Violence on the streets of Charlottesville Racial tensions sparked the violence White nationalists, neo-Nazis and members of the 'alt-right' exchange insults with counter-protesters as they attempt to guard the entrance to Lee Park during the 'Unite the Right' rally Getty Violence on the streets of Charlottesville A car plows through protesters A vehicle drives into a group of protesters demonstrating against a white nationalist rally in Charlottesville, Virginia. The incident resulted in multiple injuries, some life-threatening, and one death. AP Photo Violence on the streets of Charlottesville Rescue personnel help injured people after a car ran into a large group of protesters after an white nationalist rally in Charlottesville, Virginia AP Photo Violence on the streets of Charlottesville President Donald Trump speaks about the ongoing situation in Charlottesville, Virginia from his golf club in Bedminster, New Jersey. He spoke about "loyalty" and "healing wounds" left by decades of racism.

In a reflection of those stakes, tens of millions of dollars poured into the high-profile race, including millions from the Republican Governors Association and the Democratic Governors Association. MrObama ended his hiatus from the campaign trail to stump for Mr Northam.

A Democrat also notched a gubernatorial win in New Jersey, where Democrat Phil Murphy defeated Republican Kim Guadagno. The win wrested back control of the governor’s mansion after two terms of Gov Chris Christie, a Republican and Trump campaign surrogate.

While the contest between Mr Murphy and Ms Guadagno did not rouse the same level interest as the fight for Virginia, with Mr Murphy regularly holding a comfortable lead in polls, his victory nevertheless sent a hopeful signal to the national party. Echoes of national politics also reverberated through the race, with Ms Guadagno criticising Mr Murphy for supporting so-called “sanctuary cities” that resist cooperating with federal immigration enforcement - a favourite target for Mr Trump.