The development of nanoscale optical devices for classical and quantum photonics is affected by unavoidable fabrication imperfections that often impose performance limitations. However, disorder may also enable new functionalities, for example in random lasers, where lasing relies on random multiple scattering. The applicability of random lasers has been limited due to multidirectional emission, lack of tunability, and strong mode competition with chaotic fluctuations due to a weak mode confinement. The regime of Anderson localization of light has been proposed for obtaining stable multimode random lasing, and initial work concerned macroscopic one-dimensional layered media. Here, we demonstrate on-chip random nanolasers where the cavity feedback is provided by the intrinsic disorder. The strong confinement achieved by Anderson localization reduces the spatial overlap between lasing modes, thus preventing mode competition and improving stability. This enables highly efficient, stable and broadband wavelength-controlled lasers with very small mode volumes. Furthermore, the complex interplay between gain, dispersion-controlled slow light, and disorder is demonstrated experimentally for a non-conservative random medium. The statistical analysis shows a way towards optimizing random-lasing performance by reducing the localization length, a universal parameter.