BECAUSE he is everything that President Donald Trump is not, some out-of-state political pundits had written off Ralph Northam in Virginia’s closely watched election for governor. They suggested that Democrats were hurtling toward another embarrassment.

But Mr Northam’s identification as the anti-Trump is probably the reason he handily defeated Ed Gillespie, a former lobbyist, on November 7th. Mr Northam put in the strongest performance for a Virginia Democratic gubernatorial candidate in 32 years.

A soft-spoken paediatric neurologist who grew up on the Eastern Shore, a sandy rural spit flanked by the Chesapeake Bay and the Atlantic Ocean, Mr Northam not only led his party’s sweep for lieutenant-governor and attorney-general; he hastened huge, unexpected wins for the House of Delegates. This might tip the chamber to the Democrats for the first time in nearly 20 years. Recounts in several close races could decide party control.

Among the Democratic victors for the statehouse was Danica Roem, America’s first transgender legislator. A former newspaper reporter in the Northern Virginia suburbs of Washington, DC, Ms Roem’s win may qualify as poetic justice. She defeated Bob Marshall, a fiercely conservative Republican incumbent who wrote Virginia’s constitutional amendment banning same-sex marriage (which was subsequently overturned) and pushed for a North Carolina-like law prohibiting transgender people from using the bathroom of their choice.

There is no doubt—among Democrats and Republicans—that the Democratic triumph is a repudiation of Mr Trump, who lost Virginia in 2016 to Hillary Clinton. The president has antagonised this increasingly un-Southern Southern state with, among other things, his repeated attempts to ban travel from some Muslim-majority countries and his defence of white supremacists whose violent rally in Charlottesville this summer led to the death of a counter-protestor.

Larry Sabato, a political analyst at the University of Virginia who has studied his home state’s politics since the 1970s, said that the election is not just a manifestation of Virginia’s new multi-hued, multi-cultural character, which is on full display in its bustling, increasingly Democratic metropolitan areas. It is mostly a slap at the president.

As Mr Sabato put it in a late-night tweet directed at the pundit class: “VA hasn’t changed that much since last Nov. 8 (Hillary by 5%). The bigger explanation is a backlash to Trump and Trumpism, pure and simple.”

For this reason, the Virginia election may have far-reaching consequences. It may augur gains for Democrats in the 2018 mid-term congressional elections, which constitute the first significant opportunity for the out-of-power party to counter Mr Trump. The governor's race, as a lower-turnout, off-year affair, unfolded in a landscape similar to the one on which control of the Congress could be decided.

The implications for Virginia politics were immediate. Mr Northam’s victory and his party’s surprising gains in the legislature could portend dramatic shifts in policy, including a Medicaid-financed expansion at the state level of the Affordable Care Act. The Republican-dominated General Assembly has for four years refused appeals by Terry McAuliffe, the departing Democratic governor, to take millions in extra cash from a federal health programme for the poor to provide insurance for 400,000 uncovered Virginians.

As governor, Mr Northam also will wield a veto that would be a powerful weapon against Republicans in the next redistricting in 2021. Since 2001, the Republican Party has used hyper-partisan gerrymandering to protect its majorities, especially in the House of Delegates.

The advances by Democrats may lead to their takeover of the House before the new lines are drawn in four years. Still, a Democratic governor’s veto is a comfort for fellow partisans worried about Republican overreach in mapmaking.

That Mr Gillespie under-performed—woefully in the suburbs once friendly to Republicans—can be attributed not just to distaste for Mr Trump but Mr Gillespie’s uncertainty as a candidate. He began the race as a Trump-aloof, establishment Republican, a member of the Bush II inner circle and an advocate of a Republican Party more welcoming to immigrants. But Mr Gillespie concluded the campaign as a virtual Deplorable. He openly embraced a Trump endorsement that he said he did not seek and, in his television commercials, thundered against a handful of Spanish-speaking newcomers who have violently preyed on Northern Virginians.

Mr Gillespie’s shift seemed to have been a sign of trouble. Rather than continue efforts at persuading a shrinking number of independents to his cause, Mr Gillespie focused, instead, on driving up Republican turnout and blunting Democratic enthusiasm. He did so, in part, with commercials on radio stations that were oriented towards the African-American community, intended to raise doubts among minority voters about Mr Northam’s commitment to his black running mate for lieutenant-governor, Justin Fairfax.

But Republicans clearly had grave doubts about Mr Gillespie, even though he was a known and respected figure, having nearly defeated Mark Warner, a Democrat, in 2014 for a second term in the United States Senate. In a traditionally Republican suburb of Richmond, Chesterfield County, for example, Mr Gillespie struggled to an approximately 300-vote majority over Mr Northam. Three years ago, against Mr Warner, Mr Gillespie won the county by 8,800 votes. He needed a five-figure majority to survive this year.

It was therefore no surprise that at the close of a grim evening for Republicans, Mr Gillespie received fewer votes than his second- and third-tier running mates for lieutenant-governor and attorney-general.