The Torrance Refinery has agreed to install millions of dollars worth of new equipment that could halt the kind of power outages that have set off spectacular flaring and emergency shelter-in-place orders for the community.

The agreement, finalized Thursday with a vote of the South Coast Air Quality Management District's independent hearing board, settles a violation notice that agency staff issued against the refinery.

The worst recent outage was Oct. 11, when an outage in the Southern California Edison lines serving the neighborhood around the refinery caused a complete shutdown of the refinery. As a safety measure to prevent the buildup of gases within the plant, chemicals were burned off — causing gigantic flame to shoot out of tall flare stacks.

The Oct. 11 flare was intense and smoky, causing the city and refinery to close streets around the refinery. The city ordered residents to remain indoors for at least a half-hour. The air quality district received 67 nuisance complaints about the flaring that day.

Less intense flaring followed outages in March, when a Mylar balloon contacted power lines, and in September, when heavy fog caused electrical lines to arc and drop power.

The air quality district cited the refinery for the nuisance from the flaring, along with smoke and pollutants like sulfur oxide, nitrogen oxide, volatile organic compounds and carbon monoxide.

The refinery runs on the same 65-kilovolt power circuit that serves the surrounding neighborhood. That line had been vulnerable to outages due to common above-ground factors including dust in the lines, fog, metallic balloons, falling tree branches and vehicles hitting power poles.

The refinery has agreed with Edison and the AQMD to install an independent power line into the plant — one that would be underground, so it won't be subject to the dust, coastal fog and other problems that have caused power outages in the past. The new line would carry 220 kilovolts.

The upgrade won't be quick. It could take up to two-and-a-half years to build the new electrical equipment, but the full transfer over to the new power line is a complex task that might not be completed in up to nine years, refinery reliability manager Meir Snir said. The cost could be tens of millions of dollars — perhaps more than $50 million, Snir told the AQMD hearing board.

The agreement also calls for the refinery to upgrade its system of batteries that provide backup power during outages.

"Our City Council was not aware of the lack of the redundant [power] system," Torrance Mayor Pat Furey told the AQMD Hearing Board. "To find out that an outage in my neighborhood can cause this 700-acre behemoth to shut down, is shocking."

The refinery has a limited backup power system to keep control over certain units at the plant, but that's not strong enough to keep the refinery running — or to create steam to reduce the size and smokiness of the safety flare, Snir said.

The Torrance Refinery, the air district and SoCal Edison crafted what refinery representative Michael McDonough called "an ambitious plan to dramatically reduce the risk of loss of electricity."

Fewer outages means less flaring, he said. Flaring is smokier and more polluting during power outages because the the machines that inject steam into flare stacks to moderate the flames and smoke cannot operate. Refinery officials agreed to evaluate over the next six months the feasibility of installing a temporary generator that could inject steam into the flare stacks during power outages.

Excessive flaring was a longstanding problem at the Torrance Refinery under prior owner ExxonMobil. The AQMD's hearing board fined the company millions of dollars in past years over the nuisance from flaring.

A problem with AQMD enforcement of laws against excessive flaring is that the company has been given the option of undertaking upgrades — or paying a fine that could cost less.

"This model doesn't work," said Catherine Leys, a co-founder of FLARE, a residents refinery watchdog group. She criticized ExxonMobil's choosing to pay the fines rather than fix the underlying problem.

She urged the AQMD hearing board to move up the deadline for the refinery and utility to install the new power line.

Correction: An earlier version misstated the refinery's agreement regarding a backup steam generator system. The refinery has a six month deadline to evaluate the feasibility of installing a system.