With about 636,000 registered Democrats and nearly a half-million nonpartisan voters, Florida’s Miami-Dade County was supposed to be friendly terrain for Joe Biden — a bastion of ethnic diversity that might have helped propel him to victory in a must-win state for President Trump.

Instead, by Wednesday, Democrats were taking stock of a devastatingly disappointing performance.

Biden drew far fewer Hispanic voters than Democrats expected, carrying Florida’s most populous county of Miami-Dade by only seven percentage points, compared with the 30-point margin boasted by Democratic presidential nominee Hillary Clinton in 2016. To top it off, the Republican surge in Miami-Dade sent shock waves down the ballot, appearing to help unseat two Democratic members of Congress who represented the county, including Donna Shalala, a well-known former Cabinet secretary and president of the University of Miami.

Trump’s gains in Miami-Dade accounted for about 75 percent of his gain in net votes in the state over 2016. So rather than potentially celebrating an outright Election Day win in a huge battleground state, Biden was left to wage a drawn-out, pitched battle for votes in razor-thin contests across the country.

“It was a bloodbath,” Joe Garcia, former chairman of the Miami-Dade Democratic Party, said of his party’s showing there.

While pro-Biden ads dominated television in Florida, the GOP outworked Democrats on the ground, narrowing the voter registration gap between the two parties to its smallest margin in decades. Democrats pulled back on neighborhood canvassing until the homestretch of the campaign because of the coronavirus pandemic.

What’s more, voters from immigrant backgrounds seemed to gravitate toward Trump’s aspirational, though at times misleading statements about the strength of the economy while dismissing Biden’s dire warnings about the public health crisis.

“Our guy was talking about covid all the time and wearing a giant mask,” said Garcia, a former congressman and executive director of the Cuban American National Foundation. “The other was headlining massive rallies, talking about prosperity and looking indestructible.”

The GOP’s attacks on Democrats up and down the ballot as “socialists’’ resounded with Hispanic voters scarred by authoritarian regimes in Latin America and seeking economic opportunity in the United States.

Results of the two intensely competitive congressional races in Miami-Dade point to Trump’s improved standing among Hispanic voters.

In the district represented by Shalala, Trump lost by only three percentage points, compared to 20 points in 2016.

In Garcia’s former congressional district, one of the most Hispanic in the country, Trump won by six percentage points on Tuesday. In 2016, he lost that district by 16 points.

About half of the Hispanics in the district are Cuban American, while the rest are from Central and South America, said Republican Carlos Curbelo, who represented the district for four years after defeating Garcia in 2014.

“It’s always easy to focus on the Cuban community, but the truth is that the Trump campaign did better across all Hispanic communities,” said Curbelo, who frequently broke with Trump while serving in Congress. “Trump’s focus on economic opportunity clearly resonated, whereas most of the Democratic messaging was about how the Hispanic community is disadvantaged and an emphasis on covid, which is important but makes for a rather pessimistic campaign.”

“People want to be hopeful and think they can prosper and thrive, especially immigrant families who came to this country for that purpose,” Curbelo added.

Republican Gov. Ron DeSantis has been echoing Trump’s claims of triumph over the pandemic and demands for businesses and schools to open, despite Florida seeing one of the largest virus death tolls in the country.

“The emphasis placed on the pandemic by Biden was excessive,” said Miami-based pollster Cesar Melgoza. “People vote for their livelihoods. It was definitely a red flag for Democrats.”

Florida Democratic Party chairwoman Terrie Rizzo said: “We are confident in the ultimate victory of Joe Biden, but our Florida losses sting deep for our party, the candidates, and the 5 million Florida Democrats looking to build on the progress we have made. After Democrats secure a victory for Joe Biden, I’m looking forward to being a part of a frank conversation with the campaign and our grass-roots state and national partners to address data, messaging and turnout issues that contributed to Florida’s losses, and where our party goes from here.”

The Trump administration has been aggressively courting the Venezuelan community in Miami-Dade as that country descended into chaos, poverty and violence over the past two years. Flanked by large Venezuelan and American flags, Trump delivered a major speech denouncing President Nicolás Maduro and declaring the “twilight hour of socialism” in February 2019 at Florida International University. That theme was bookended one week before the election by his daughter, Ivanka Trump, who at a Miami rally said: “Today, I bring a message from my father: America will never be a socialist country.”

Such appeals resonated with Miami voter Maria Todd, 49, who moved to the United States as a child during Panamanian dictator Manuel Antonio Noriega’s regime in the 1980s. The former teacher hosts a YouTube show called “American Values” and recoiled at what she perceived as the Democratic nominee’s offer of “free” health care under the Affordable Care Act.

“Biden speaks clearly like a chavista-type person, and Miami knows socialism, dictators and communists,” Todd said, referring to Hugo Chávez, the former Venezuelan leader. “That’s not history to us. That’s something that has tainted our lives forever. We recognize it when we see it.”

Republican strategist Ryan Tyson said he concluded from his work for the state GOP this election cycle that Hispanic voters also were turned off by the Black Lives Matter protests over the summer. Trump’s jabs at what he characterized as far-left rioters and his repeated though false suggestions that Biden wants to “defund” the police appear to have won over some voters.

“Since we have suffered the undermining of the rule of law in Venezuela, I’ve been really concerned about the situation I saw in [Portland, Ore.,] and other cities in the U.S.,” said Boris Noguera, a Trump activist in Miami and originally from Caracas. “I don’t agree at all with defunding the police, so that’s why I have been motivated for Trump, because he supports institutions and the rule of law.”

Biden’s loss sparked debate over whether Florida still qualifies as a swing state and led to perennial calls for new Democratic leadership in a state where Republicans have dominated the capital for two decades. Democrat Anna Eskamani, a state representative in central Florida, said the party invested too much on consultants and advertising — including more than $100 million by former New York mayor Mike Bloomberg — and not enough on basic field operations and door-knocking.

The Democrats’ current 134,242 voter registration advantage in Florida is less than half of its cushion in 2016, when Trump carried the state by fewer than 113,000 votes.

Democrats retreated to phone banks and digital outreach when the pandemic hit in March and didn’t ramp up in-person campaigning until the final month of the race. The Trump campaign said it knocked on more than 4 million doors in the state.

On the other hand, Biden allies spent twice as much money as Republicans in Florida and more than three times as much in the last three weeks of the campaign.

“All that money for Joe Biden here didn’t do any good,” Eskamani said. “There definitely needs to be a complete cleaning of the house in the leadership of the Democratic Party. We should be organizing 24/7, and not just in campaign season.”

One of the few bright spots for Miami-Dade Democrats was a victory in the countywide mayoral election, but the race was closer than anticipated.

“We ran a ground-and-pound, grass-roots, door-knocking race and it mattered,” Tyson said. “The field program by the Trump campaign was historic in Florida. We never saw the Biden people anywhere.”

Rozsa reported from Florida.