Kate Harrison, the councilwoman who introduced the Berkeley ban, said that dozens of public officials from around the country had contacted her for advice about how to enact similar legislation.

The 22 other California cities and counties that followed Berkeley’s lead, including San Jose, the country’s 10th-largest city, have done so with building codes that encourage electric wiring and appliances rather than ban gas outright.

Brookline’s ban, which applies to new construction and gut renovations but makes some exemptions for buildings like research laboratories, awaits review by the Massachusetts attorney general before it can become law.

In nearby Cambridge, Mass., city officials have already held hearings on an ordinance that would block natural gas connections in new buildings and those being substantially renovated.

But the ordinances are facing some pushback.

The Massachusetts chapter of NAIOP, a commercial real estate association, for instance, has joined groups that represent the gas and restaurant industries in opposing the measure. Tamara Small, the organization’s chief executive, said the new legislation was premature, and she predicted that the Cambridge ban would be challenged in court if it was passed because of conflicts with state legislation.

“We’re not saying it’s not possible at some point,” she added. “But we’re moving too quickly.”

Some real estate companies, however, are already experimenting with all-electric construction, prompted by their own environmental goals or goaded by investors who “want to know what they are doing to address climate risk in their portfolios,” said Billy Grayson, executive director of the Center for Sustainability and Economic Performance at the Urban Land Institute, a real estate think tank.

Kilroy Realty, a large commercial developer in Los Angeles, has a portfolio that includes 17 percent all-electric buildings, said Sara Neff, the company’s senior vice president for sustainability. Ms. Neff expects that figure to grow.