The search for habitable environments and biomarkers in exoplanetary atmospheres is the holy grail of exoplanet science. The detection of atmospheric signatures of habitable Earth-like exoplanets is challenging owing to their small planet–star size contrast and thin atmospheres with high mean molecular weight. Recently, a new class of habitable exoplanets, called Hycean worlds, has been proposed, defined as temperate ocean-covered worlds with H2-rich atmospheres. Their large sizes and extended atmospheres, compared to rocky planets of the same mass, make Hycean worlds significantly more accessible to atmospheric spectroscopy with JWST. Here we report a transmission spectrum of the candidate Hycean world K2-18 b, observed with the JWST NIRISS and NIRSpec instruments in the 0.9–5.2 μm range. The spectrum reveals strong detections of methane (CH4) and carbon dioxide (CO2) at 5σ and 3σ confidence, respectively, with high volume mixing ratios of ∼1% each in a H2-rich atmosphere. The abundant CH4 and CO2, along with the nondetection of ammonia (NH3), are consistent with chemical predictions for an ocean under a temperate H2-rich atmosphere on K2-18 b. The spectrum also suggests potential signs of dimethyl sulfide (DMS), which has been predicted to be an observable biomarker in Hycean worlds, motivating considerations of possible biological activity on the planet. The detection of CH4 resolves the long-standing missing methane problem for temperate exoplanets and the degeneracy in the atmospheric composition of K2-18 b from previous observations. We discuss possible implications of the findings, open questions, and future observations to explore this new regime in the search for life elsewhere.