MANTOLOKING, N.J. — Two wealthy New Jersey shore towns that were among the hardest hit by Superstorm Sandy nearly two years ago began building a 4-mile-long steel wall Thursday, an expensive effort that the state says is needed to protect the communities but that some residents and environmentalists oppose.

State and local officials watched Thursday as work began where the Atlantic Ocean tore through the sand and cut a channel into Barnegat Bay on the other side of the barrier island the communities share, destroying a major state highway and part of a crucial bridge during the Oct. 29, 2012, storm.

The steel wall will be buried in sand and span the length of Mantoloking, where virtually all of its 521 homes were damaged or wiped off the map, and the oceanfront section of Brick Township, its neighbor to the south, where gas-fed fires burned much of what Sandy did not wash away.

“We stood in this spot where the inlet was cut,” said Robert Martin, New Jersey’s environmental protection commissioner. “We knew we needed to do more than just put some more sand on the beach.”

The 45-foot-long steel sheets will be driven 30 feet into the ground and eventually covered by sand, which will form a dune system 22 feet above sea level. In December or January, the Army Corps of Engineers will begin a beach replenishment project to widen the beach in front of the wall to 300 feet.

Short of knocking down all the remaining homes and relocating the CEOs, stockbrokers, attorneys and other wealthy residents of Mantoloking, where life revolves round the local yacht club, the wall was chosen by state and local officials as the best way to protect it from similar damage in the future.

Because New Jersey officials pitched it as a way to protect Route 35, newly rebuilt for $200 million after the storm, the Federal Highway Administration is paying 80 percent of the project cost from Sandy relief funds, with the state contributing the rest. But the $23.8 million project cost is only the first of many expensive bills.

Environmentalists say the wall will worsen erosion if the beach in front of it is not constantly replenished, citing decades of studies worldwide that show waves smashing against hard structures like metal or rock walls or bulkheads will scour the sand in front of them, worsening erosion there. “This sea wall will not work, and will only make things worse,” said Jeff Tittel, president of the New Jersey Sierra Club.