BOSTON — Massachusetts utility regulators slapped three power companies with penalties totaling nearly $25 million on Tuesday for their handling of widespread outages caused by two major storms in 2011.

The record fines against National Grid, NStar and Western Massachusetts Electric Co. were imposed after a lengthy investigation by the state into how the utilities planned for and responded to Tropical Storm Irene and a surprise October snowstorm. Hundreds of thousands of customers lost electricity and many waited longer than a week for the lights to come back on after each storm.

By far, the biggest penalty was assessed against National Grid, which was fined nearly $8.2 million for Irene and more than $10.5 million for the snowstorm — a total of 18.7 million.

Ann Berwick, chairwoman of the Department of Public Utilities, cited “systematic and fundamental failures in how the company planned for and responded to both storms.”

“We also found that many of the problems with National Grid’s response have persisted for some time and the company had been warned about in the past,” Berwick added.

The investigation revealed inadequate planning for the storms, as well as failures in responding to public safety threats posed by toppled electrical wires, she said. National Grid was also cited for lapses in communication with its customers and municipal officials after the storms, and for not prioritizing facilities such as nursing homes while restoring power.

National Grid said in a statement it was reviewing the decision and evaluating its options. The company can appeal to the state’s highest court.

“We understand customers were frustrated by the outages resulting from the devastating storms in 2011 and we share that frustration,” the company said, adding that it has implemented many changes in emergency planning that were put in practice during the more recent Superstorm Sandy.

NStar and Western Massachusetts Electric (WMECO), both divisions of Hartford, Conn.-based Northeast Utilities, said they would appeal the penalties.

NStar was fined $4.1 million — $2.2 million for Irene and $1.9 million for the snowstorm. WMECO was fined $2 million, and only for its response to the snowstorm.

Regulators said that while both companies met most standards for response, neither did an adequate job of clearing downed wires that posed a major safety hazard for police and firefighters along with the general public.

“We strongly disagree with the department and are disappointed that they dismissed the tireless effort put forth by our employees to respond to customers after these historic storms,” said Werner Schweiger, NStar’s president, in a statement announcing the company’s intention to appeal.

Irene alone damaged 80 percent of the NStar’s overhead circuits, Schweiger said, forcing the utility to essentially rebuild its power grid even as it was trying to restore electricity.

Peter Clarke, president of WMECO, said his company also strongly disagreed with the findings, saying it responded to the emergencies in a “safe, responsible and methodical way under extremely difficult conditions.”

Berwick did praise the utilities for a stronger response to Sandy. That storm did not cause the same level of damage in Massachusetts as in several other northeastern states.

Attorney General Martha Coakley said the penalties, while smaller than the combined $30 million she had sought against the companies, sent a “clear signal” that utilities would be held accountable for failures in preparing for and responding to major outages.

“Our investigation found that the utilities’ preparation for these storms was woefully inadequate and their slow responses to downed wires created dangerous public safety situations across the (state),” Coakley said. She also supported a recommendation by the DPU for a future review of all service quality standards.

A 2009 state law authorized regulators to impose fines for storm response. Earlier this year, lawmakers voted to require that any future penalties be returned to customers in the form of rate relief. Utilities can decide whether to return the money through refund checks or credits on future bills.

The steepest penalty against a utility in a previous, non-storm related case was $8 million against National Grid in 2009, officials said.

“Regulated utilities must be accountable to the residents they serve,” Gov. Deval Patrick said Tuesday. “I trust (the penalties) will encourage the utilities to refocus their efforts on preparation for and response to weather events in the future.”