Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

The governor of California on Thursday evening issued a statewide stay-at-home order to help combat the spread of the coronavirus.

The order, which takes effect Thursday night, asks residents to leave their homes only when necessary. It will remain in place until further notice.

Gov. Gavin Newsom's announcement came about an hour after officials in Los Angeles County ordered people to stay home except for essential needs or jobs and for indoor shopping malls and nonessential retail to close.

San Francisco and surrounding counties had previously issued orders to stay at home to stop the spread of the coronavirus and the illness it causes, COVID-19.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Newsom said the statewide order is consistent with the local orders. Places like grocery and convenience stores, delivery restaurants, gas stations, pharmacies, banks and laundromats will remain open.

Bars, nightclubs, theaters, gyms and convention centers have been ordered closed.

The goal is to encourage "social distancing," which health experts have stressed can slow the spread of the disease and keep health systems from being overwhelmed.

CA is issuing a statewide, mandatory STAY AT HOME order.



Those that work in critical sectors should go to work. Grocery stores, pharmacies, banks and more will stay open.



We need to meet this moment and flatten the curve together.



Go to https://t.co/xtXFwVeWc2 to learn more. — Gavin Newsom (@GavinNewsom) March 20, 2020

The governor said he hopes people will voluntarily obey the order to stay at home if possible, saying, "There's a social contract here."

"People, I think, recognize the need to do more and to meet this moment," Newsom said.

California, which has a population of around 40 million, is among the first states to order restrictions statewide. Earlier in the week, Nevada said that all non-essential businesses should close for 30 days.

"We project that roughly 56 percent of our population — 25.5 million people — will be infected with the virus over an eight week period," Newsom wrote in a letter to President Donald Trump dated Wednesday.

Full coverage of the coronavirus outbreak

Newsom said Thursday evening: "That number in and of itself shouldn't be overly alarming — the vast majority of us, the overwhelming majority of us, won't have symptoms, will be perfectly fine. But there is a subset that we're concerned about" who will be more seriously affected.

The state has more than 870 cases and has had 17 deaths linked to the illness, according to an NBC News count of reported cases, which includes those who have recovered, those who have died and those repatriated to the U.S. from other countries.

New York and Washington state have more cases.