Democrats were celebrating on Wednesday after winning big in governor, state legislative, county and mayors’ races across the country on a night full of symbolism, a year to the day from Donald Trump’s election as president.

Their victories included three major elections – Virginia governor, New Jersey governor and New York City mayor – and the first openly transgender person elected and seated in a state legislature.

It was the party’s most cheering night at the ballot box since Barack Obama’s re-election five years ago. They handed Republicans what Obama once memorably called a “shellacking” when on the receiving end. They now have the wind at their backs for the 2018 midterm elections and a decent shot at taking back the House of Representatives.

“The Democratic party is back, my friends,” the Democratic national committee chairman, Tom Perez, declared.

It was a stinging rebuke to Trump as he arrives in China in an attempt to play global statesman. The so-called resistance had shown it could amass vast women’s marches and skewer the president with witty epigrams on Twitter. Now it heeded Obama’s plea to go beyond hashtags and memes by showing up. “This is what happens when the people vote,” Obama tweeted.

The results also represented a corrective, a restoration of some kind of equilibrium and a reminder that America as a whole did not make a sudden lurch to the populist right on 8 November 2016. Trump lost the popular vote by nearly 3 million that day and won the Oval Office because of the arcane electoral college. Republican strategists warned at the time that this was hardly grounds for confidence in total dominance for all time, although Trump celebrated it again with a tweet on Wednesday:

Congratulations to all of the ”DEPLORABLES” and the millions of people who gave us a MASSIVE (304-227) Electoral College landslide victory! pic.twitter.com/7ifv5gT7Ur — Donald J. Trump (@realDonaldTrump) November 8, 2017

The New York Times columnist Frank Bruni wrote: “Just when we needed a sign that his America is not all of America, Virginia came to the rescue and gave us a vivid one. And I guarantee you that the Republicans up for re-election in 2018 saw it, shuddered and will spend the next weeks and months trying to figure out just how much trouble their party is in and precisely how to repair it.”

Democratic joy was mixed with palpable relief. Defeat in Virginia and New Jersey, both of which backed Clinton over Trump last year, would have been catastrophic and prompted gloomy cliches of “being out of power for a generation”. Virginia’s comfy northern suburbs include commuters to Washington DC, where Trump supporters are harder to find than tickets to Hamilton. The newest local celebrity is Juli Briskman, a cyclist who gave the president’s motorcade the middle finger. Losing Virginia would have suggested that there was something very, very wrong, that a tectonic plate had shifted.

In the end, they did more than just not lose. The governor’s race wasn’t even close. Democrat Ralph Northam beat Republican Ed Gillespie by nine percentage points, a much wider margin than expected and significantly bigger than Clinton’s win over Trump. Steve Kornacki, a voting analyst on the MSNBC channel, dubbed it “the revenge of the suburbs” after a long 12 months of Trump.

The president himself, who had largely stayed out of campaigning for the biggest election day of 2017, found time while travelling in Asia and confronting North Korea’s nuclear threat to tweet: “Ed Gillespie worked hard but did not embrace me or what I stand for.”

Surprisingly, Democrats also wiped out a 32-seat Republican advantage in Virginia’s house of delegates, with recounts likely to determine control. Poetically, Bob Marshall, one of the chamber’s longest-serving and most conservative members, who earlier this year sponsored a bill that would have limited the bathrooms transgender people can use, was unseated by Danica Roem, a Democrat and former journalist who is transgender.

In New Jersey, term-limited Republican Chris Christie, the first governor to endorse Trump for president and now the most unpopular state chief executive in the country, must hand over the mansion keys to a Democrat after Phil Murphy trounced the Republican lieutenant-governor, Kim Guadagno.

The Democratic mayors of New York and Boston won re-election easily. In Hoboken, New Jersey, Ravinder Bhalla became one of the first Sikh mayors of an American city. A Democrat beat a Republican incumbent in Manchester, New Hampshire, to become the city’s first female mayor. Charlotte got its first African American Democratic female mayor. And voters in Maine approved a referendum to expand Medicaid for low-income adults, defying the Republican governor, Paul LePage. The omens are very good for next year, especially as the party not occupying the White House always tends to do well.

Dave Wasserman, US House editor of the Cook Report, tweeted: “You can’t really look at tonight’s results and conclude that Democrats are anything other than the current favorites to pick up the US House in 2018.”

The greatest danger now is complacency. This “tsunami election”, as the Richmond Times-Dispatch put it, could create the illusion that division between the Clinton and Bernie Sanders wings is healed, that the leadership vacuum left by Obama is no problem, that the tide of anti-Trump sentiment will drift inexorably into office by itself.

But for Republicans things are much worse. The party succumbed to Trump’s divisive nativism and is still embroiled in a civil war. Despite controlling the White House, Senate and House, it has failed to pass major legislation. Now it has experienced the bitter taste of defeat at the ballot box and faces a terrible dilemma in the midterms. It can embrace the president, field Steve Bannon-backed candidates and complete its transformation from the party of Lincoln to the party of Trump, or it can ostracise him as Democrats did Obama in 2014, which did not work out well.

Or it can try to have it both ways, as Gillespie did in Virginia, playing the anti-immigration card in the south-west while seeking to appear moderate in the north. It was a perilous tightrope walk and he fell to the ground with a splat.