Maryland Gov. Larry Hogan (R) (Linda Davidson/The Washington Post)

Jubilant Maryland Democratic leaders had one clear message for Republican Gov. Larry Hogan after Tuesday night's Democratic sweep: You're next.

Victories in Virginia, along with the ouster of Republican mayors in two Maryland cities, illustrated a powerful surge of opposition to President Trump, analysts say, and should serve as a warning sign to Hogan and the state GOP in 2018.

The popular governor “had to wake up this morning a heck of a lot less confident than he did Tuesday,” said Todd Eberly, a political science professor at St. Mary’s College. “There is an in­cred­ibly energized Democratic electorate out there.”

In Annapolis, the state capital, Mayor Mike Pantelides (R) lost by 24 percentage points to Democrat Gavin Buckley, a progressive and political newcomer. In Frederick, Alderman Michael O’Connor (D) ousted Mayor Randy McClement (R) by a margin of 22 percent. Those elections were the main partisan races among several town and city contests in Maryland and Virginia.

Kathleen Matthews, Democratic Party chair in Maryland. (Evelyn Hockstein/For The Washington Post)

“I didn’t think that concern about what was happening nationally with the Republican Party would have filtered down this far,” said McClement, who in the past has enjoyed support from the city’s Democratic majority. “This time it seems like people really voted along party lines.”

Maryland GOP chair Dirk Haire, however, dismissed the idea that Trump's unpopularity would affect the reelection chances of Hogan, a moderate who didn't vote for the president and has criticized his administration repeatedly.

"He's the second-most-popular governor in the country," Haire said. Democratic attempts to tie Hogan to Trump haven't been successful , he added, and "I don't know why they think it could be in the next 12 months."

The Annapolis and Frederick races were the Maryland Democratic Party's first test under chair Kathleen Matthews, who was brought on to rebuild following crushing defeats in 2014 and a bitter U.S. Senate primary last year.

“A blue wave is building,” Matthews said in a statement.

The party faces multiple obstacles, including Hogan’s record-high approval ratings, his huge campaign war chest and a crowded field of little-known primary candidates.

Still, polls have shown that many Democrats, even those who think Hogan is doing a good job, would prefer to vote for a Democrat in the wake of last year's presidential election. Democrats have a 2-to-1 party registration advantage in the state, and more than 6 in 10 Maryland voters disapproved of Trump's performance in a recent poll.

“It will be a hard thing to overcome, even at a 65 percent approval rating,” Eberly said. “People aren’t voting on the individual candidate. They aren’t voting on who’s on the ballot, but who isn’t on the ballot — and that’s Donald Trump.”

Jim Barnett, Hogan's campaign manager, said in a statement that Maryland voters "know that Gov. Hogan is radically different in both tone and substance than what they see coming out of Washington, D.C. His moderate, bipartisan approach is the antidote to what ails the country, and represents the sort of politics Marylanders want more of from their leaders."

Hogan is under fire from Democrats for his decision to support fellow Republicans in Tuesday's election, including defeated Virginia gubernatorial candidate Ed Gillespie .

Maryland Del. Carlo A. Sanchez, chair of the state's Legislative Latino Caucus, called on Hogan to rescind his endorsement of Gillespie and to denounce campaign ads in that race and in an Annapolis City Council race that tied immigration policy to a surge of gang violence.

Democratic gubernatorial candidate Jim Shea weighed in with a tweet on Wednesday, accusing Hogan of supporting “Gillespie’s racist and Trumpian campaign.”

“Gillespie went down yesterday. Up next, Larry Hogan,” the tweet said.

The allegations of racist campaign tactics in Annapolis centered on Republican James Appel, a Hogan ally who sent mailers that tried to tie Democrat Marc Rodriguez to the growth of the MS-13 gang in the city. The campaign literature accused Rodriguez of having a weak position on gang violence.

Rodriguez defeated Appel on Tuesday to become the first Latino elected official in Annapolis. He said he was excited to see voters “overwhelmingly reject the negative and fearmongering tactics that were at play.”

Appel said any suggestion the ads were racist is “absurd.” MS-13, he said, is a “huge problem in Annapolis that needs to be paid more attention to.”

Elsewhere in Maryland, council incumbents in College Park — who were challenged largely because of their support for a charter amendment that would allow undocumented immigrants to vote in local elections — appeared to retain their seats, according to preliminary results.

“There was a fear that some candidates tried to spark about immigrants and diversity,” said Mayor Patrick Wojahn, who defeated City Council member and charter amendment opponent Mary Cook. “But College Park voters strongly pushed back.”

The council voted in favor of the charter amendment in September but fell short of the two-thirds majority required for passage. Wojahn, who supported the amendment, said the discussion is tabled.

Elsewhere in Maryland, Takoma Park Mayor Kate Stewart and Gaithersburg Mayor Jud Ashman, who both ran uncontested, will return to office. Two incumbents in Takoma Park, who were also uncontested, will be joined on the City Council by newcomer Kacy Kostiuk, who fills a seat vacated by Rizzy Qureshi, who did not seek reelection.

In Greenbelt, Emmett Jordan received the most votes in the City Council race and is expected to be selected as mayor by his fellow council members. Among the other winners was Colin A. Byrd, known for his efforts to rename the football stadium at the University of Maryland in College Park.

In Virginia, incumbents David F. Snyder, Dan Sze and Marybeth Connelly won reelection to the Falls Church City Council. Ross Litkenhous will replace Karen Oliver, who did not run for reelection.

In Leesburg, Vanessa Maddox defeated Josh Thiel in the nonpartisan Town Council race.