In the past decade, observations from space and the ground have found water to be the most abundant molecular species, after hydrogen, in the atmospheres of hot, gaseous extrasolar planets1-5. Being the main molecular carrier of oxygen, water is a tracer of the origin and the evolution mechanisms of planets. For temperate, terrestrial planets, the presence of water is of great importance as an indicator of habitable conditions. Being small and relatively cold, these planets and their atmospheres are the most challenging to observe, and therefore no atmospheric spectral signatures have so far been detected6. Super-Earths—planets lighter than ten Earth masses—around later-type stars may provide our first opportunity to study spectroscopically the characteristics of such planets, as they are best suited for transit observations. Here, we report the detection of a spectroscopic signature of water in the atmosphere of K2-18 b—a planet of eight Earth masses in the habitable zone of an M dwarf7—with high statistical confidence (Atmospheric Detectability Index5 = 5.0, 3.6σ (refs. 8,9)). In addition, the derived mean molecular weight suggests an atmosphere still containing some hydrogen. The observations were recorded with the Hubble Space Telescope/Wide Field Camera 3 and analysed with our dedicated, publicly available, algorithms5,9. Although the suitability of M dwarfs to host habitable worlds is still under discussion10-13, K2-18 b offers an unprecedented opportunity to gain insight into the composition and climate of habitable-zone planets.