MIAMI — The salty breeze and ocean waves have beckoned stir-crazy residents of the coast back to their beloved beaches, social distancing norms be damned.

But how to prevent beach blankets and lawn chairs from becoming new founts of coronavirus infection has become a flash point for governors in Florida, California and other coastal states, who must balance demands from constituents for relief from the escalating spring heat against the horrified reaction of the general public to photos of sweaty, swimsuit-clad bodies packed towel to towel.

Gov. Gavin Newsom of California stepped in on Thursday to shut down the beaches in Orange County, rolling back earlier attempts at giving people there a chance to stroll along the shore while staying a safe distance away from one another. Broad swaths of sand were packed over the weekend with crowds, with many people flocking from neighboring Los Angeles and San Diego Counties, where the beaches had been off-limits.

“This disease isn’t going away,” Mr. Newsom said at a news conference, noting that the pandemic had claimed at least 95 lives in the state in the past 24 hours.

The county-by-county approach in California and Florida, perhaps the two states most defined by their iconic coastlines, has resulted in a patchwork of evolving rules that differ day to day, and even from beach to beach. Figuring out how to keep coastal areas safe represents one of the toughest dilemmas for state officials as they begin to move out of coronavirus lockdowns.

In Florida, Gov. Ron DeSantis has resisted pressure to close all the beaches, insisting that the decision should be made locally — and that people who consider the beach their backyard deserve a respite from being cooped up at home.

When photos of beachgoers in the Jacksonville area prompted “#FloridaMorons” to trend on social media, Mr. DeSantis dismissed the mockery as misguided elitism from outsiders who were unwilling to accept that not all areas of Florida have been hit by the coronavirus as hard as the region from Miami to West Palm Beach, where the beaches remain closed.

“For those who try to say you’re morons, I’ll take you over those who criticize you every day of the week and twice on Sunday,” Mr. DeSantis told Jacksonville residents in a news conference last week.

Beaches in Galveston, Texas, will reopen on Friday, following Gov. Greg Abbott’s phased reopening order, which permits outdoor activities as long as people take precautions to “minimize in-person contact with people who are not in the same household.”

In New Jersey, Gov. Phil Murphy said this week that the state would look at opening beaches based on how this weekend’s reopening of state parks goes. Some city officials have discussed a coordinated opening of beaches by Memorial Day.

“If folks do what we’re asking them to do, that will have a huge impact on our ability to take what I call baby steps,” Mr. Murphy said. “Let’s see how parks go, but no decisions yet or imminently on beaches.”

Alabama was set to reopen its beaches on Thursday afternoon under the governor’s new “safer-at-home” order, which limits gatherings to fewer than 10 people and requires six feet between groups from different households.

Beaches are vital to the economy in coastal states, drawing residents and tourists to seaside restaurants and shops that are a lifeblood to small coastal towns. Even with most businesses closed, beaches were among the few places where residents who cannot afford pools could cool off when temperatures in California reached 100 degrees last week. Parts of Florida have also been experiencing record heat.

“The beach is sort of this sacred space, almost, for Florida,” said Craig Pittman, the author of five books about the state. “A lot of people who grew up here think of it as, ‘That’s my beach.’ If you can’t go to the beach, what is Florida?”

But beaches are also gathering places where it is all too easy to spot a friend and approach to say hello, getting much too close to prevent virus transmission. In densely populated counties, there are simply not enough lifeguards or police officers to stop visitors from engaging in old social habits.

“Once you open them, there’s a good chance that they would be wall-to-wall with people,” said Mayor Dan Gelber of Miami Beach, whose shoreline remains closed. “Because we have 7.5 miles of open beaches and so many public access points, enforcing capacity is difficult, if not impossible.”

Beach safety patrols in Volusia County, home to Daytona Beach, an emblematic spring break town, issued more than 1,200 warnings on Sunday to people violating rules that limit activities to exercise.

“We’ll drive away and people will come up right behind us and set up a tent and chairs and just hang out,” said Captain Tamra Malphurs, a spokeswoman for the beach safety ocean rescue. “People are getting quarantine fatigue.”

Deciding how to proceed has pitted elected leaders, medical professionals and neighbors against one another. Public records from St. Johns County in Florida, home to St. Augustine, show that the beaches there remained open in March even after the medical examiner urged the county administrator to shut them down because the rate of coronavirus cases was too high.

Photos of crowded Florida beaches during spring break had prompted national outrage. Organizers of the oceanfront Winter Party Festival in Miami Beach during that period reported that dozens of people developed symptoms or tested positive for the coronavirus.

“Protect the residents,” wrote Dr. Deanna A. Oleske, the associate medical examiner in St. Johns County. “Close the beaches. Please.”

With beaches in neighboring counties closed at the time, a record number of people streamed into the St. Johns County shore, public officials said in emails obtained by Columbia University’s Brown Institute for Media Innovation and reviewed by The New York Times. Residents called and wrote elected commissioners, begging them to shut the beaches down.

Only after an eye-catching aerial photo on March 28 showed empty beaches in closed Duval County and crowded sand just over the county line in St. Johns County did St. Johns close its shore. Chief Robert A. Hardwick of the St. Augustine Beach Police Department wrote county commissioners the next day that the situation had been a “crisis” and a “public safety concern.”

The beaches have since reopened in coordination with Duval County. People have not had trouble complying with social distancing, Michael Ryan, a St. Johns County spokesman, said on Thursday.

No travel restrictions exist among Florida counties except for the Florida Keys, which have banned access to nonresidents. When Key West announced it would reopen its beaches for local residents, the roadblocks some 100 miles north saw an uptick in people trying to drive down, not understanding that the beaches were still closed to out-of-town visitors.

Groups of people flocked to the beach in Key West as soon as it opened on Monday. On Wednesday, clusters of friends were at Smathers Beach in groups of up to six people. They maintained distance from other groups but not from one another. Police officers wearing masks monitored the area.

Kristof Ivanov and his co-workers at the Conch Republic Seafood Company restaurant, now closed, said they rushed to the beach after weeks of being stuck inside.

“We are being disciplined. I think everyone is fine,” he said. “We are ready to wear masks when we go to the grocery store and places like that.”

His friend Aaron Delong said keeping the beaches closed was illogical.

“I think it was foolish,” he said, “when every specialist, every doctor, every reporter, says vitamin D is so good for you. A day as perfect as this, why wouldn’t we be outside getting fresh air, getting sunlight?”

Daniel W. Uhlfelder, a lawyer from Santa Rosa Beach who tried to sue the Florida governor to demand statewide beach closures, was planning to tour beaches in the Panhandle in a Grim Reaper costume to draw attention to the risk of virus spread. He said he was most worried that people from areas of the South hit hard by the coronavirus will be driving to the area for a beach break.

“It’s going to be a public health disaster,” Mr. Uhlfelder said. “It’s going to be a magnet.”

In California, Mr. Newsom weighed closing the beaches along the state’s entire coastline, according to a memo leaked on Wednesday night from the California Police Chiefs Association to municipal authorities in Orange County, south of Los Angeles, where the beach issue has been most contentious.

Local officials pushed back, arguing that a one-size approach would be counterproductive, as did California conservatives, who have already sued over the Democratic governor’s stay-at-home orders. Mr. Newsom stopped well short of a statewide closure, ordering what he called “a very short-term adjustment” to the one county he said had fallen short of social distancing guidelines.

Still, the Huntington Beach City Council voted on Thursday night to sue the state over the beach ban, and the City Council in nearby Newport Beach appeared poised to follow, according to local media reports. Photographs of crowded beaches in both cities this past weekend had drawn ridicule from some online, but both cities had stood firm in keeping their beaches open, with Newport Beach urging more police officers and lifeguards to enforce social distancing along the shoreline.

The governor has pleaded with Californians to slow the spread of the virus by staying home, despite the temptations of seawater and sunny weather. Photographs of umbrellas and surfers dotting the shoreline of some Southern California beaches showed that many residents had not heeded his requests.

Up north, Sheriff William Honsal of Humboldt County, which has 110 miles of California’s 840 miles of coastline, said a statewide beach shutdown would have felt “like a real slap in the face” to places that have not experienced Orange County’s crowds.

“What’s good for Southern California may not be good for Northern California,” he said.

In Orange County, John Pope, a spokesman for the city of Newport Beach, said before Mr. Newsom’s announcement that a state-ordered beach closure could inflame divisions in the community among civil libertarians and residents who fear further spread of the virus.

“This is going to get very political very fast,” Mr. Pope said.

Patricia Mazzei reported from Miami, Shawn Hubler from Sacramento and Thomas Fuller from San Francisco. Frances Robles contributed reporting from Key West, Fla., and Nicholas Bogel-Burroughs and Michael Cooper from New York. Derek Kravitz, a data journalist at Columbia University’s Brown Institute for Media Innovation, contributed reporting from New York.