AimTo disentangle the role of evolutionary history, competition and environmental filtering in driving the niche evolution of four closely related subterranean spiders, with the overarching goal of obtaining a mechanistic description of the factors that determine species' realized distribution in simplified ecological settings.LocationDinaric karst, Balkans, Europe.TaxonDysderidae spiders (Stalita taenaria, S. pretneri, S. hadzii and Parastalita stygia).MethodsWe resolved phylogenetic relationships among species and modelled each species' distribution using a set of climatic and habitat variables. We explored the climatic niche differentiation among species with n‐dimensional hypervolumes and shifts in their trophic niche using morphological traits related to feeding specialization.ResultsClimate was the primary abiotic factor explaining our species' distributions, while karstic and soil features were less important. Generally, there was a high niche overlap among species, reflecting their phylogenetic relatedness, but on a finer scale, niche shifts explained the realized distribution patterns. Trophic interaction was another important factor influencing species distributions – the non‐overlapping distributions of three morphologically indistinguishable Stalita species is seemingly the outcome of competitive exclusion dynamics. The distribution of the fourth species, Parastalita stygia, overlaps with that of the other species, with several instances of coexistence within caves. As inferred from the morphology of the mouthparts, the mechanism that minimizes interspecific competition is the shift in the trophic niche of P. stygia towards a more specialized diet.Main conclusionsWe showed that similarity in niches only partly correlated with the phylogenetic distance among species, and that overlaps in species distributions are possible only when a parallel shift in diet occurs. Our work emphasized how even simplified environments still maintain the potential for diversification via niche differentiation. Ultimately, we provide an ecological explanation for the diversification of life in an important hotspot of subterranean diversity.