Donald Trump retook the White House with a big boost from economically distressed communities—places full of workers he has called “the forgotten men and women who have been neglected.”

More surprising: He also ran up gains in many places where workers and businesses are thriving. Compared with his 2020 loss, he improved his vote share in more-affluent coastal enclaves and suburban areas, as well as in lower-income border counties and rural areas that have long backed the GOP.

His advance presents a major challenge to Democrats , who have increasingly relied on the nation’s professional-class voters to counteract collapsing support in small-town and rural America. On Tuesday, that calculation failed.

Using a variety of metrics—including income, poverty and education levels—the bipartisan think tank Economic Innovation Group ranked the economic health of the more than 3,000 U.S. counties. It rated them on a five-level scale from “distressed” to “prosperous.”

The counties where Trump’s support grew most—by at least 2 percentage points, including many places with more robust gains—were largely in distressed, or at-risk, communities. They include such counties as Starr, in Texas, where the median household income is far below the Texas level and poverty is much higher. The shift in Starr—the second most heavily Hispanic county in the U.S., and located on the border—also reflected Trump’s major gains with this population.

Trump’s strong performance in distressed places fits with his often-dour campaign-trail description of the economy under President Biden. The election came as many metrics, including inflation , which has cooled significantly from highs in 2022, indicated an economy in solid shape. But many voters didn’t feel those effects and liked Trump’s focus on such issues as curbing illegal immigration and cutting taxes. And those at the lower rungs of the economic ladder struggled to pay for the basics, including food and housing.

But Trump also gained ground in more-prosperous counties, such as New Jersey’s Bergen, Long Island’s Suffolk and Nassau, and Pennsylvania’s Bucks County. Preliminary counts show that Vice President Kamala Harris ’s vote declines, compared with Biden’s totals in 2020, often played a significant role in boosting Trump’s margins.

These patterns helped Trump sweep all seven of the closely contested swing states.

Meanwhile, Harris’s modest share gains compared with Biden in 2020 were especially concentrated among prosperous counties.

These include Henry County, in the Atlanta area, which has an 11% higher median household income than the state, census data shows.

Democrats have increasingly become a party of college-educated, white-collar voters—who are clustered in places where Trump made inroads this year. That has heightened their challenge when it comes to finding votes to win in vital swing states like Pennsylvania and Wisconsin, where Trump already draws strong support from working-class voters.

“The typical county that went to Harris was more white, more educated and higher income than the typical Clinton or Biden county,” said John Lettieri , Economic Innovation Group’s chief executive, referring to the prior two Democratic nominees. The Trump base, he said, has become a “broader, multiracial, working-class type coalition.”

When it comes to occupation, Trump’s biggest gains were especially concentrated in places where blue-collar jobs are prevalent. But he also made broad advances in places with big shares of white-collar jobs.

Income tells a similar story. Harris gained ground among voters with more than $100,000 in household income, compared with her party’s 2020 showing. The hurdle for Democrats is that less than a third of people who cast ballots this year have income that high, according to AP VoteCast, a survey of 2024 voters.

With so much of the nation tipping toward Trump, the presidential election suggests that the nation’s urban-rural divisions—the political differences between the big metropolitan areas and small-town and rural places—have narrowed.

This could shape Trump’s governing agenda, since the president-elect won majorities in several big counties across the Sunbelt, said Mark Muro , a senior fellow at the Brookings Institution’s Brookings Metro. But it could also lead to some challenging dynamics over such issues as technology-sector support for highly skilled immigrant workers, he said.

“This wave is a sign of strength for Trump, but it might also lead to some new tensions within his base,” Muro said.

Democrats still won in counties representing a far bigger chunk of the U.S. economy. Counties won by Harris account for 60% of gross domestic product, according to Brookings’s analysis of preliminary data . But that is down from 71% four years ago, as Trump flipped several populous counties, including New York’s Nassau, Florida’s Miami-Dade and likely Maricopa in Arizona, where Trump was leading in still-incomplete results.

Write to Jon Kamp at Jon.Kamp@wsj.com , Andrew Mollica at andrew.mollica@wsj.com , Aaron Zitner at aaron.zitner@wsj.com and Brian McGill at brian.mcgill@wsj.com