LOS ANGELES — President Trump woke up here in the land of earthquakes on Wednesday morning, but he was 2,500 miles away from the tremor that was really shaking his party.

While the president hobnobbed on Tuesday night with wealthy donors in the exclusive enclave of Beverly Park, the voters in the suburbs south of Pittsburgh were in revolt, giving the Democratic candidate a narrow victory in a special election in Pennsylvania that was taking on outsize proportions.

Just as they did outside Birmingham and Montgomery, Ala., in December, and Richmond, Va., and Washington in November, energized and angry suburban voters were swamping the Trump stalwarts in the more rural parts of those regions, sending a clear message to Republicans around the country.

While Republican turnout in a district that Mr. Trump won in 2016 by 20 percentage points was healthy, Democrats showed again that they could tap unions and other traditionally friendly groups to get their voters out in droves. The N.A.A.C.P. helped win Attorney General Jeff Sessions’s former Alabama Senate seat for Doug Jones in December. Organized labor, once seen as fractured and feckless in the Trump era, gave the Democrat Conor Lamb his edge in Pennsylvania.