Taking a page from more than a dozen communities in California, Brookline, MA, has become the first in the state to ban oil and natural gas piping in new building construction.

Brookline’s action followed a town meeting in which all but three of more than 200 residents voted for Article 21, the new bylaw. Sponsors claimed Brookline needed “to do something about climate change,” a familiar refrain in California, where large and small municipalities have undertaken similar actions already this year.

Brookline, a wealthy suburb encircled by Boston and the birthplace of President Kennedy, still needs approval by the Massachusetts Attorney General’s Office.

Fuel oil is still a major source of home heating in Massachusetts, although natural gas increasingly has been incorporated in new buildings and used for power generation. New England’s grid operator earlier this year indicated it was preparing for a future without new gas infrastructure, and has raised the possibility that the region’s electricity system won’t have enough energy to meet demand on the coldest days of winter.

The Northeast Gas Association and other industry trade organizations indicated the ban likely will be challenged in court. Representatives of gas utility National Grid also opposed Brookline’s action.

“The gas network has an enduring role to play in bringing about a clean energy future, and customers should have the ability to choose their energy source,” said National Grid spokesperson Robert Kievra.

“We have been looking at new technologies to decarbonize our gas network in tandem with the electric network,” but the utility recognizes “that Brookline’s town meeting reflects an important segment of our customers and the communities we serve. That’s why we are so committed to, and already taking actions to mitigate climate change. “

National Grid, he said, is committed to “collaborate with our stakeholders on the best ways to reach our shared decarbonization goals.”