ATTORNEY GENERAL MAURA HEALEY’S office on Tuesday reluctantly shot down a bylaw approved by the town of Brookline that would have barred the installation of most fossil fuel infrastructure in any new buildings or significant rehabs of existing buildings.

In a 12-page ruling, Healey applauded the town’s bid to start addressing greenhouse gas emissions but said the bylaw approved overwhelmingly by town meeting members in November is preempted by the state building code, gas code, and a law giving the Department of Public Utilities oversight of the sale and distribution of natural gas in Massachusetts.

“If we were permitted to base our determination on policy considerations, we would approve the bylaw,” Healey said in her opinion. “Much of the work of this office reflects the Attorney General’s commitment to reducing greenhouse gas emissions and other dangerous pollution from fossil fuels, in the Commonwealth and beyond. The Brookline bylaw is clearly consistent with this policy goal.”

But Healey said she was forced to disapprove the bylaw because it conflicts with existing state laws and codes.

Rep. Tommy Vitolo of Brookline, who helped craft the bylaw and built support for it, called the decision a setback. He said the bylaw was a common-sense, baby-step solution to climate change. “When you’re in a hole, the first thing you do is stop digging,” he said.

Vitolo said the bylaw would have barred oil and natural gas pipes into new buildings or rehabs for the purpose of heating water or creating heat. He said the bylaw was initially drafted to also bar natural gas pipes for cooking, but that provision was dropped in response to consumer opposition.

Vitolo said Healey’s ruling suggests the place to start with a ban on fossil fuel infrastructure in new buildings is Beacon Hill, but he wanted to talk to his colleagues and House Speaker Robert DeLeo before filing any legislation.

The Brookline bylaw was opposed by gas utilities and real estate developers. Tamara Small, the CEO of NAIOP Massachusetts, the commercial real estate development association, called the decision “a huge win for development statewide, as at this stage of technology, natural gas bans would block important housing and economic development projects from advancing and would be extremely detrimental to the Commonwealth’s economy.”

A shift to heat and hot water generated using electricity is consistent with the state’s long-term plan for reducing greenhouse gas emissions. That goal revolves around using electricity to power vehicles and heat homes and businesses while moving the regional power grid away from power plants running on natural gas and relying instead on electricity supplied by offshore wind farms, solar, hydroelectricity, and nuclear power.

According to a dashboard maintained by the New England power grid operator, the region has a long way to go to reduce its reliance on fossil fuels. As of Tuesday afternoon, 69 percent of the region’s power was coming from natural gas power plants, 17 percent from nuclear plants, 7 percent from hydro, 6 percent from renewables, and 1 percent from oil.