In House races, Democratic candidates are likely to face Republican attacks tying them to Representative Nancy Pelosi of California, the unpopular Democratic minority leader, and to liberal policies, like single-payer health care, that are causing divisions in the Democratic ranks.

But for Republicans, the bad news was not likely to end with Tuesday’s results.

Congressional Republicans on Wednesday were bracing for a new wave of retirements just one day after another pair of veteran House members, Representative Frank A. LoBiondo of New Jersey and Representative Ted Poe of Texas, declared they would not seek re-election. Already, 29 House Republicans have said they will not run again, while just seven Democrats have announced plans to retire.

Mr. Dent, channeling the exasperation of his colleagues, suggested an exodus might be imminent. “Do they really want to go through another year of this?” said Mr. Dent, a leader of his caucus’s moderate wing, who has announced he will not run again.

In the White House, electoral defeat gave way to a shifting series of explanations: Mr. Trump’s first reaction was to savage Ed Gillespie, the defeated Republican candidate for governor in Virginia, on Twitter. By Wednesday morning, two presidential advisers acknowledged antipathy toward Mr. Trump would probably drive Democratic turnout in 2018.

But by Wednesday afternoon, the story changed again: At a White House briefing, aides dismissed the importance of New Jersey and Virginia in either 2018 or 2020. One White House official blamed congressional Republicans, asserting that swing voters on Tuesday embraced Democrats because they were frustrated that lawmakers had not moved on the president’s agenda.

But some of the most competitive House races of the 2018 midterms will take place in the two states. In New Jersey, Republicans will struggle to retain Mr. LoBiondo’s seat and must protect such imperiled incumbents as Leonard Lance, Tom MacArthur and Rodney Frelinghuysen. In Virginia, the district of Representative Barbara Comstock, a Republican, went 56 percent to 43 percent for Lt. Gov. Ralph S. Northam, the Democrats’ triumphant candidate for governor. Mr. Northam also captured 51 percent of the votes in the district of Representative Scott Taylor, a freshman Republican from Virginia Beach.