RICHMOND — Dominion Energy would have to clean up four coal ash ponds around Virginia — some dating to the 1930s, all of them leaking — under legislation that Gov. Ralph Northam, a bipartisan group of legislators and the utility backed Thursday.

The company would have to fully excavate the unlined ponds, which collectively hold more than 27 million cubic yards of the toxic ash and which environmentalists say are polluting ground­water.

Coal ash, which is generated when coal is burned to create electricity, contains significant amounts of arsenic, mercury and heavy metals. The bill requires that 25 percent of the ash be recycled into a cleaner form for use in concrete and other building materials. The rest would be moved to modern, lined landfills.

The legislation also would limit how much of the cost Dominion could pass on to rate payers to about $5 a month per customer.

Dominion, the state’s largest utility and most prolific political donor, has stored coal ash in ponds in four sites around the state — in Prince William, Chesterfield and Fluvanna counties and the city of Chesapeake.

Environmentalists have contended for years that the ponds were sending toxins into the groundwater, posing a danger to people and wildlife. Monitoring wells near the company’s Possum Point power plant, near the Potomac River in Prince William, have shown elevated levels of nickel, boron and other metals in the groundwater.

Dominion has been under federal orders since 2014 to safely dispose of the pollutant. The company had sought permission to leave the coal ash in place and cap it, but now it has agreed to a more lasting solution, said Sen. Scott A. Surovell (D-Fairfax), whose district includes Possum Point.

“The ponds were already leaking, they were unlined, and there was no assurance that [capping] would work forever,” Surovell said. “If we didn’t do anything, Dominion had to spend $1.7 billion [to comply with the federal order]. We required them to spend an extra $1 billion to clean it up in a way that we were sure would not cause any future problems.”

Dominion spokesman David Botkins confirmed in an email that the company wanted to fix what he called a “legacy issue.”

“Dominion Energy supports the comprehensive agreement reached by the Governor, legislative leaders, and members of the General Assembly that accomplishes clean closure, minimizes truck traffic, and prudently manages customer costs for the closing of ash ponds at our power stations,” he wrote.

Michael Town, executive director of the Virginia League of Conservation Voters, has been battling Dominion for years to improve how it manages what he described as “lakes full of toxic coal ash.”

“Can you imagine what the environmental protections were in the 1930s? That is how this stuff is being managed today,” he said. “And we do not think that’s appropriate, and I think most Virginians would agree.”

The legislation comes at a time when Dominion is facing a political backlash, including opposition over a gas pipeline project as well as a law, passed at the company’s behest last year, limiting the State Corporation Commission’s ability to oversee electricity rates. Some populist-style Democrats and Republicans have sworn off donations from the company, although the company and its supporters in the legislature contend that the state’s electricity rates are a relative bargain.

“I think they recognized that they’ve had a hard couple years with public perception,” Town said. “They recognized that politics in Virginia are changing. Maybe that’s what brought them to the table.”

The legislation requires the company to work with local governments to minimize truck traffic and to give local workers preference for jobs created at the sites. It also would direct the company to hook up private properties to municipal water systems for free if the coal ash has polluted their wells.

Northam (D) announced the legislation alongside House Speaker Kirk Cox (R-Colonial Heights) and a bipartisan group of delegates and senators.

“We can’t afford an environmental disaster in Virginia like the one North Carolina suffered from the Duke Energy coal ash spill on the Dan River,” Northam said, referring to an incident in 2014.

“This agreement is an example of what we can achieve when we work together across party lines to do what’s best for the people Virginia,” Northam said. “I look forward to seeing this proposal passed in both chambers and signing it into law.”

Cox said the legislation fit with his focus on “practical solutions for kitchen table issues. And there’s probably no bigger issue for a lot of us back in our home districts.”

Under rules announced in 2014, the U.S. Environmental Protection Agency regulated hundreds of coal ash dumps for the first time, requiring extensive testing and monitoring of some disposal sites and forcing others to shut down. The ash had been exempted from federal waste-management regulations by Congress in the 1970s.

Three of the coal plants with ponds, including Possum Point, have either been converted to gas or shut down. The one in Chester, in Chesterfield County, still burns coal and that ash now goes into a landfill.