In the field of cold quantum matter, control of the motional degrees of freedom of both neutral and charged gas-phase molecules has been achieved for a wide range of species 1-11 . However, cooling of the internal degrees of freedom remains challenging. Recently, transfer to the internal ground state by sophisticated optical techniques has been demonstrated for neutral alkali dimers created in single quantum states from ultracold atoms 12-15 . Here we demonstrate cooling of the rotational degree of freedom of heteronuclear diatomic molecules with a thermal distribution of internal states, using a simple, robust and general optical-pumping scheme with two low-power continuous-wave lasers. With trapped and translationally cooled hydrogen deuteride (HD + ) molecular ions as a model system, we achieve 78(4)% rovibrational ground-state population. The rotationally, vibrationally and translationally cold molecular ion ensemble is suitable for a number of applications, such as generation of long-lived coherences or frequency metrology of fundamental constants 16,17 .The study of cold molecular systems promises new insights and advances in many fields of physics and physical chemistry. As in atomic physics, the key to tapping the full potential of molecules is the ability to accurately control the external and internal degrees of freedom of the particles. The complex internal structure of molecules has however so far precluded direct application of many techniques developed for trapping and cooling of atoms, demanding modified or completely new approaches. Now, a large toolbox for trapping and cooling the motional degrees of freedom of both neutral and charged molecules is available 18 . Although general schemes for cooling the internal degrees of freedom of molecules have been proposed 19,20 , the most general method available at present is cryogenic buffer-gas cooling, which is efficient only for molecules in the vibrational ground state and limits the translational temperature to a few hundred millikelvin 7 . Coherent transfer to the rovibrational ground state 11-14 is most suitable when most of the molecules are initially in the same quantum state, as is the case for molecules produced by associating cold atoms.For heteronuclear molecular ensembles for which the population is distributed among many rotational levels in the v = 0 vibrational manifold, optical pumping has been proposed as an approach to rotational cooling 21,22 . We demonstrate here that a scheme using two laser fields driving a fundamental and an overtone vibrational electric dipole transition 21 yields a large ground-state population and briefly discuss the applicability of the scheme to various diatomic molecular species. Figure 1 shows the energy levels (without hyperfine structure) and electric dipole transitions of the HD + molecule relevant for the experiment. The initial internal-state distribution is given by a Boltzmann distribution reflecting thermal equilibrium with the T ∼ = 300 K blackbody radiation field emitted by the experimental Inst...