  Context. Despite being a prominent subset of the exoplanet population
discovered in the past three decades, the nature and provenance of
sub-Neptune-sized planets are still one of the open questions in exoplanet
science. Aims. For planets orbiting bright stars, precisely measuring the
orbital and planet parameters of the system is the best approach to distinguish
between competing theories regarding their formation and evolution. Methods. We
obtained 69 new radial velocity observations of the mid-M dwarf G 9-40 with the
CARMENES instrument to measure for the first time the mass of its transiting
sub-Neptune planet, G 9-40 b, discovered in data from the K2 mission. Results.
Combined with new observations from the TESS mission during Sectors 44, 45, and
46, we are able to measure the radius of the planet to an uncertainty of 3.4%
(Rb = 1.900 +- 0.065 Re) and determine its mass with a precision of 16% (Mb =
4.00 +- 0.63 Me). The resulting bulk density of the planet is inconsistent with
a terrestrial composition and suggests the presence of either a water-rich core
or a significant hydrogen-rich envelope. Conclusions. G 9-40 b is referred to
as a keystone planet due to its location in period-radius space within the
radius valley. Several theories offer explanations for the origin and
properties of this population and this planet is a valuable target for testing
the dependence of those models on stellar host mass. By virtue of its
brightness and small size of the host, it joins L 98-59 d as one of the two
best warm (Teq ~ 400 K) sub-Neptunes for atmospheric characterization with
JWST, which will probe cloud formation in sub-Neptune-sized planets and break
the degeneracies of internal composition models.
