Haematopoietic stem and progenitor cells (HSPCs) require a specific microenvironment, the haematopoietic niche, which regulates HSPC behaviour1,2. The location of this niche varies across species, but the evolutionary pressures that drive HSPCs to different microenvironments remain unknown. The niche is located in the bone marrow in adult mammals, whereas it is found in other locations in non-mammalian vertebrates, for example, in the kidney marrow in teleost fish. Here we show that a melanocyte umbrella above the kidney marrow protects HSPCs against ultraviolet light in zebrafish. Because mutants that lack melanocytes have normal steady-state haematopoiesis under standard laboratory conditions, we hypothesized that melanocytes above the stem cell niche protect HSPCs against ultraviolet-light-induced DNA damage. Indeed, after ultraviolet-light irradiation, unpigmented larvae show higher levels of DNA damage in HSPCs, as indicated by staining of cyclobutane pyrimidine dimers and have reduced numbers of HSPCs, as shown by cmyb (also known as myb) expression. The umbrella of melanocytes associated with the haematopoietic niche is highly evolutionarily conserved in aquatic animals, including the sea lamprey, a basal vertebrate. During the transition from an aquatic to a terrestrial environment, HSPCs relocated into the bone marrow, which is protected from ultraviolet light by the cortical bone around the marrow. Our studies reveal that melanocytes above the haematopoietic niche protect HSPCs from ultraviolet-light-induced DNA damage in aquatic vertebrates and suggest that during the transition to terrestrial life, ultraviolet light was an evolutionary pressure affecting the location of the haematopoietic niche.