For weeks, subway riders at the Herald Square station in Manhattan have detected a foul stench similar to rotten eggs—or worse.

Paul Golin was tempted to blame a fellow passenger. “I thought the source was sitting next to me,” said Mr. Golin, 47 years old, a nonprofit executive who caught a whiff of the odor on his F train commute from the Park Slope area of Brooklyn.

An investigation by the Metropolitan Transportation Authority uncovered the apparent suspect: sewage leaking inside a tunnel that carries the F, M, D and B subway lines along Sixth Avenue to the station at 34th Street, MTA officials said.

But an MTA spokesman said authorities have yet to pinpoint the source or type of the gas.

The state-run MTA has been working with the city’s Department of Environmental Protection, both agencies said.