One moment, Dorothy Peteet stood on a mat of squishy grass in Idlewild marsh, on the edge of Jamaica Bay in southern Queens. The next moment she sank to her hips in the cool, sulfuric muck. She was neither grossed out nor surprised.

“Yes, this happens,” Dr. Peteet, one of the world’s foremost experts on marshes, said. “I don’t think I remembered to bring any towels.”

A saltwater marsh is an in-between place. Twice a day, it’s flooded by the tide. When the tide is low, a marsh may appear to be solid grassy ground, but under the cordgrass it is riven with creeks and rivulets, mud snails, diamondback terrapins and fiddler crabs. For centuries, New Yorkers viewed Jamaica Bay’s swamps as smelly barriers to progress, fit to become garbage dumps only when they couldn’t be drained and paved into highways and airports.

In recent decades, scientists like Dr. Peteet have recast the marshes as environmental marvels, providing a rare habitat for thousands of species, filtering the water and preventing contamination by locking tons of industrial pollutants away in their soggy underground vaults.

Most important, Jamaica Bay’s marshes serve as New York City’s best defense against climate change, said Dr. Peteet, a paleoecology researcher at NASA and a professor at Columbia University. As the oceans warm and storms grow more violent, the marshes act like a cushion, absorbing energy from big waves before they crash into people’s homes and threaten to suck whole neighborhoods into the sea.