Residents in six San Francisco Bay Area counties will be confined to their homes for the next three weeks under a new shelter-in-place order aimed at curbing the spread of the coronavirus.

The mandate, which goes into effect Tuesday and will affect nearly 7 million people, orders residents to avoid unnecessary travel and only leave their homes for food, medicine and exercise, according to county officials who made the announcement.

Bartender Lyndsay Przybyl, center rear, pours drinks for customers at Lush Lounge in San Francisco, Sunday, March 15, 2020. 

Bartender Lyndsay Przybyl, center rear, pours drinks for customers at Lush Lounge in San Francisco, Sunday, March 15, 2020.  (AP)

It affects the counties of San Francisco, Marin, Santa Clara, San Mateo, Alameda and Contra Costa, as well as the city of Berkeley.

"I know today's order is a radical step. It has to be. We need to act now, all of us, to protect the public health," said Dr. Grant Colfax, director of the San Francisco Department of Public Health.

"We must move aggressively and immediately," said San Jose Mayor Sam Liccardo, whose city is the epicenter of Bay Area outbreak. "History will not forgive us for waiting an hour more."

San Francisco Mayor London Breed criticized what she called a "terrible response" by federal officials.

"We can't sit back and wait for the federal government to do anything. Unfortunately, they have not been as proactive as they should in recognizing this is a crisis throughout the world," she said.

The order tells people to work from home unless they provide essential services such as public safety, sanitation and medical services. Pharmacies and banks will remain open, while restaurants will be open only for takeout.

The dramatic step came as officials across California took increasingly aggressive measures to separate people and contain the spread of coronavirus, prompting millions of the state's oldest and youngest residents to stay home on Monday.

Freeways normally jammed with rush-hour drivers flowed freely. Long lines persisted at some grocery stores despite officials saying there's no need to hoard supplies.

A man and woman wear masks while riding a Cable Car in San Francisco.

A man and woman wear masks while riding a Cable Car in San Francisco. (AP)

On Sunday, Gov. Gavin Newsom urged the state's 5.3 million people who are 65 and older and those with chronic health conditions to isolate at home. He also called for all bars, wineries, nightclubs and brewpubs to close.

Los Angeles Mayor Eric Garcetti ordered restaurants to only offer pickup, delivery and drive-thru service. He also closed gyms, movie theaters, bowling alleys and arcades.

DEEP PARTISAN DIVIDE OVER CORONAVIRUS THREAT: POLL

Newsom said an estimated 85 percent of California's 6 million public school students will be out of their classrooms this week. Many districts are arranging for meal pickups for families that depend on schools for breakfast and lunch. Movie theaters, casinos, and theme parks were told to limit crowd sizes and keep patrons separated.

California has confirmed at least 335 cases of the virus and six deaths. The virus usually causes only mild or moderate symptoms, such as fever and cough, but can be deadly for older people and those with underlying health conditions.

CLICK HERE TO GET THE FOX NEWS APP

The state has increased the number of available hospital beds and will reopen shuttered medical centers in the coming days. Newsom said he was pushing to move many of the state's 108,000 homeless people indoors, using motels and 450 state-owned trailers set up before the outbreak.

The Associated Press contributed to this report.