We report the confirmation of a transiting planet around the bright, inactive M0.5 V star TOI-1235 (TYC 4384-1735-1, V = 11.5 mag), whose transit signal was detected in the photometric time series of Sectors 14, 20, and 21 of the TESS space mission. We confirm the planetary nature of the transit signal, which has a period of 3.44 d, by using precise radial velocity measurements with CARMENES and HARPS-N spectrographs. A comparison of the properties derived for TOI-1235 bs with theoretical models reveals that the planet has a rocky composition, with a bulk density slightly higher than Earths. In particular, we measure a mass of M_p = 5.9+/-0.6 M_Earth and a radius of R_p = 1.69+/-0.08 R_Earth, which together result in a density of rho_p = 6.7+1.3-1.1 g/cm3. When compared with other well-characterized exoplanetary systems, the particular combination of planetary radius and mass puts our discovery in the radius gap, a transition region between rocky planets and planets with significant atmospheric envelopes, with few known members. While the exact location of the radius gap for M dwarfs is still a matter of debate, our results constrain it to be located at around 1.7 R_Earth or larger at the insolation levels received by TOI-1235 b (~60 S_Earth), which makes it an extremely interesting object for further studies of planet formation and atmospheric evolution.