“This is not the moment for half-measures, and history won’t forgive us for waiting an hour more,” Mr. Liccardo said.

Residents are being ordered to stay home except for essential reasons, which include buying food; people can also leave for outdoor activities including “walking, hiking or running” and caring for a pet.

Mayor Joe Goethals of San Mateo put it this way: “I’m asking people to go home with their families and to stay there until they are told otherwise.”

Mayor London Breed of San Francisco said “necessary” government offices and “essential stores” would be allowed to remain open. The order, she said in a Twitter post, would be effective at midnight.

In a state very familiar with disasters, from wildfires to earthquakes, the leaders of California found themselves in recent days confronting something altogether different, with no playbook to lean on.

[Want to get our daily newsletter California Today by email? Here’s the sign-up.]

The state that has pioneered the technology that allows people to connect remotely is quickly realizing how much human contact is important not only for the economy but also for the well-being of its residents.

In the time it takes for an email to drop in an inbox, or a news alert to flash across an iPhone screen, school districts, one after another, were closing. Movie productions were shutting down, premieres canceled. At the ports, terminals were shuttered, as fewer ships, loaded with consumer goods and parts for American factories, set sail from China. And exports, poultry and oranges, were piling up on the docks.