It was a good night to be a Democrat, as the party's candidates won a slate of closely watched races stretching from Virginia to Washington state on Tuesday.

At the gubernatorial level, Democrat Ralph Northam defeated Republican Ed Gillespie in a hotly contested race in Virginia, which many analysts viewed as a referendum on President Donald Trump.

The victory was "a backlash to Trump and Trumpism, pure and simple," wrote Larry Sabato, director of the Center for Politics at the University of Virginia.

Larry Sabato tweet: Dear Pundit Friends, please stop attributing this D landslide in VA to "changing demographics". 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. #VAGov

In New Jersey, Democrat Phil Murphy won a gubernatorial race against Republican Lt. Gov. Kim Guadagno, who struggled to get out from under the shadow of the deeply unpopular outgoing governor, Republican Chris Christie.

Moving down the ballot, Democrats in Virginia also won competitive races for lieutenant governor and attorney general. In January of 2018, Democrat Justin Fairfax will be sworn in as lieutenant governor, making him the first African American elected to statewide office in Virginia since 1989. And the state's attorney general, Democrat Mark Herring, was reelected after a bitter campaign.

In Virginia's legislature, Democrats flipped at least 10 seats in the Republican controlled House of Delegates, and it was still unclear late Tuesday night which party would control the chamber, which has been under a Republican majority since 1999. Razor thin margins in at least five races Tuesday made it likely that provisional and absentee ballots would need to be counted, potentially delaying results.

The party's victories in Virginia energized Democrats across the country, as Virginia governor Terry McAuliffe (D) told The Washington Post. "This, what a sparkplug," he said. "This is the revitalization of the Democratic Party in America. This isn't just about Virginia tonight."

In Washington state, control of the state senate also went to Democrats, when Manka Dhingra won a special election, giving the party a one-seat majority, and putting the state government fully under the control of Democrats, who hold the governorship and the majority in Washington's House of Representatives.

Mayoral races, too, produced a swath of Democratic victories, most notably in New York City, where mayor Bill de Blasio cruised to victory over Republican Nicole Malliotakis.

Voters in Charlotte, N.C. elected the city's first African American female mayor, Democrat Vi Lyles. In Hoboken, N.J., City Councilman Ravi Bhalla (D) beat five other candidates to become the city's first Sikh mayor, according to The Associated Press.

Democrats attributed much of their success Tuesday to an energized party base that is deeply opposed to Trump's policies and his rhetoric. Former Vice President Joe Biden captured what many in the party were feeling:

Joe Biden tweet: "A resounding defeat tonight for President Trump. Voters around the country rejected the ugly politics we have seen this past year. Instead, they chose candidates who unite and inspire us."