Safeway has agreed to pay $8 million after authorities accused the grocery giant of breaking gasoline-leak prevention laws at its 71 California gas stations, including 18 in the Bay Area, according to a Friday announcement.

Although investigators found no leaks, California Attorney General Rob Bonta called Safeway’s gas stations across the state “an accident waiting to happen,” and claimed, “We averted disaster.”

Bonta accused Safeway of “recurring failure” to implement required systems and processes for preventing leaks, which include primary and back-up containment equipment for stored underground fuel, continuous monitoring of tanks and use of leak-detection technology.

Safeway, in the settlement, did not deny or admit wrongdoing, and did not immediately respond to an inquiry about the allegations that led to the settlement.

A single pinprick-sized leak in an underground gas tank can leak 400 gallons of fuel in a year, and one gallon can contaminate more than a million gallons of groundwater, Bonta said Friday during a news conference.

Gas stations subject to the agreement’s provisions include two each in San Jose and Alameda; and one each in Campbell, Morgan Hill, Dublin, Livermore, Pleasanton, San Leandro, Antioch, Byron, Hercules, Pleasant Hill, San Ramon, Novato, Dixon and Vallejo.

Five Bay Area district attorneys’ offices are among the 29 county district attorneys’ offices across California that are to share $5.1 million of the penalty paid by Safeway. Solano’s office is to get $696,544; Contra Costa’s is to receive $593,775; Alameda’s is to get $60,900; Santa Clara’s is to receive $40,600; and Marin’s is to receive $10,150. Bonta’s office is to get $1,450,181.

The Solano and Contra Costa allocations are based on their substantial roles in the investigation along with Safeway’s presence and alleged violations in their counties, and the other offices received allocations based on Safeway’s presence and alleged violations in their counties, Bonta’s office said.

Under the agreement, Safeway will ensure its facilities have leak-detection sensors “capable of detecting a leak at the earliest possible opportunity” and equipped with alarms. The company will also have to monitor potential water-intrusion into containment areas around underground tanks, among other actions required under state health and safety laws.

The allegations against Safeway arose after DA offices in Contra Costa, Solano, Placer, Sacramento and San Joaquin counties notified Bonta’s office about potential violations of state law regulating gas storage, Bonta’s office said, adding that it couldn’t confirm or deny whether his office was looking into possible similar problems at other companies’ gas stations.

“Enforcement of underground storage tank violations at gas station chains is an ongoing area of cooperation between our office and our partner district attorneys and a priority for the attorney general,” Bonta’s office said.

California’s attorney general has settled several cases against major gas chains over underground fuel storage, which have included a $14 million penalty against BP in 2016, a $11.5 million penalty against Phillips 66 and ConocoPhillips in 2015, and a $24.5 million penalty against Chevron in 2011.