SAN FRANCISCO — Millions of people were poised to lose electricity throughout northern and central California after Pacific Gas & Electric Co. announced Tuesday it would shut off power in the largest preventive outage in state history to try to avert wildfires caused by faulty lines.

PG&E said it would begin turning off power to 800,000 customers in 34 counties starting after midnight Wednesday amid forecasts of windy, dry weather that create extreme fire danger. To the south, Southern California Edison also said Tuesday that more than 106,000 of its customers in parts of eight counties could face power cuts.

Outages are planned in more than half of California’s 58 counties, although not everyone in those counties will have their power cut.

The news came as residents in the region’s wine country north of San Francisco marked the two-year anniversary of deadly wildfires that killed 44 and destroyed thousands of homes. San Francisco is the only county in the nine-county Bay Area where power will not be affected.

The utility had warned of the possibility of a widespread shut-off Monday, prompting residents to flock to stores for supplies as they prepared for dying cellphone batteries, automatic garages that won’t work and lukewarm refrigerators.

Flashlights, batteries and propane tanks for barbecues were in high demand as people prepared for an outage that PG&E said may last “several days.”

“We sold out of lanterns this morning. The shelf is completely empty,” said Howard Gibbs, the manager at Ace Hardware in the town of Lafayette, 20 miles (32 kilometers) east of San Francisco. “We’ve got just a few flashlights left, and we’re down to our last couple propane tanks, too.”

Oakland Mayor Libby Schaaf asked residents Tuesday not to clog 911 lines with non-emergencies and urged people to be prepared. The city canceled all police officers’ days off in preparation for the outages.

“We all know the devastation that fires can cause,” she said.

In 1991, a grass fire torched the Oakland Hills, killing 25 people and destroying more than 3,000 homes.

PG&E said it was informing customers by text and email about where and when the power would be cut. But its website, where it directed people to check whether their addresses would be affected, was not working most of the day Tuesday after being overloaded with visitors.

Gov. Gavin Newsom said PG&E had no choice given that it would have faced liability for fire damage but he said customers are right to feel outraged. The utility needs to upgrade and fix its equipment so massive outages aren’t the norm going forward, he said.

“No one is satisfied with this, no one is happy with this,” he said.

The outage will also affect portions of the agricultural Central Valley, the state’s northern and central coasts and the Sierra Nevada foothills where a November wildfire blamed on PG&E transmission lines killed 85 people and devastated the town of Paradise.

Jennifer Siemens, who lost her home in Paradise, rents a house in the nearby town of Oroville and said she was bracing for a third blackout in a month.

Siemens had her car gassed up, had stocked up on bottled water and flashlights and made sure all the family’s electronic devices were fully charged.

“What’s wrong with the power lines that they have to do this so much?” asked Siemens. “We don’t want any more fires, obviously, but I feel like they are going a little overboard.”

Winds can knock down live wires and power poles or drive trees and other vegetation into contact with them — and some of California’s most destructive blazes in recent years were started by PG&E power lines.

But the planned outages will not be limited to fire-prone areas because the utilities must turn off entire distribution and transmission lines to much wider areas to minimize the risk of wildfires.

San Francisco-based Pacific Gas & Electric sought bankruptcy protection in January, saying it could not afford an estimated $30 billion in potential damages from lawsuits stemming from recent wildfire. As part of ongoing bankruptcy litigation, last month the company agreed to pay $11 billion to a group of insurance companies representing claimants from deadly Northern California wildfires in 2017 and 2018.

In Southern California, the largest numbers of potentially affected customers were in Los Angeles County and to the east in San Bernardino and Riverside counties.

Public agencies throughout the region were urging people to prepare by buying water and non-perishable food, getting a full tank of gas, having cash at hand and parking vehicles outside garages or making sure they know how to manually open their garage doors.

The California Department of Forestry and Fire Prevention said it increased staffing in preparation for extreme fire weather and what was expected to be the strongest wind event so far this fire season.

“With some of the most destructive and deadliest fires occurring October through December, we need Californians to not be complacent,” said Cal Fire Chief Thom Porter in a news release. “Residents need to be ready to evacuate at a moment’s notice in the event of a wildfire.”

At the Dollar General store in Paradise, people were buying candles, gas cans, ice, flashlights, batteries and canned food and the store ran out of ice chests Tuesday morning, said manager Ben Humphries.

Humphries, who moved to Oroville with his family after losing his home in Paradise, said his family lost power two times already in the last month and he was making sure they had enough fuel for their generator and plenty of ice in coolers.

But he said there was a sense of irony to PG&E’s aggressive action in the area now, after the company opted not to turn off the power ahead of the Nov. 8 fire that wiped out Paradise.

“I understand their concerns but in my opinion it’s too little too late, we already had our town burned to the ground,” Humphries said.