MOUNT PLEASANT, S.C. — From a couch on the back deck of a dockside restaurant, the Beatles playing in the background and a breeze blowing off the water, Joe Cunningham gestured to Shem Creek.

“This could be the reality here, of oil rigs and oil spills off the beach,” Mr. Cunningham said. “An oil spill could just decimate the area, and all of a sudden instead of people coming to Charleston, South Carolina, they high-tail it down to Florida or somewhere else.”

Offshore drilling might not captivate voters in most parts of the country, but it did here. For months, Mr. Cunningham called for the restoration of a federal ban as his Republican opponent, Katie Arrington, talked about immigration and warned that a vote for him would be a vote for Nancy Pelosi’s “San Francisco values.” And in November, Mr. Cunningham, 36, defeated Ms. Arrington in a House district that last elected a Democrat four years before he was born.

It was one of the biggest upsets of the midterms, and it turned on an ideal issue for a candidate who, before he became a lawyer, was an ocean engineer.