Engineering the electromagnetic environment of a nanometre-scale light emitter by use of a photonic cavity can significantly enhance its spontaneous emission rate, through cavity quantum electrodynamics in the Purcell regime. This effect can greatly reduce the lasing threshold of the emitter, providing a low-threshold laser system with small footprint, low power consumption and ultrafast modulation. An ultralow-threshold nanoscale laser has been successfully developed by embedding quantum dots into a photonic crystal cavity (PCC). However, several challenges impede the practical application of this architecture, including the random positions and compositional fluctuations of the dots, extreme difficulty in current injection, and lack of compatibility with electronic circuits. Here we report a new lasing strategy: an atomically thin crystalline semiconductor--that is, a tungsten diselenide monolayer--is non-destructively and deterministically introduced as a gain medium at the surface of a pre-fabricated PCC. A continuous-wave nanolaser operating in the visible regime is thereby achieved with an optical pumping threshold as low as 27 nanowatts at 130 kelvin, similar to the value achieved in quantum-dot PCC lasers. The key to the lasing action lies in the monolayer nature of the gain medium, which confines direct-gap excitons to within one nanometre of the PCC surface. The surface-gain geometry gives unprecedented accessibility and hence the ability to tailor gain properties via external controls such as electrostatic gating and current injection, enabling electrically pumped operation. Our scheme is scalable and compatible with integrated photonics for on-chip optical communication technologies.