Understanding the ecology of environmentally acquired and multi-host pathogens affecting humans and wildlife has been elusive in part because fluctuations in the abundance of host and pathogen species may feed back onto pathogen transmission. Complexity of pathogen-host dynamics emerges from processes driving local extinction of the pathogen, its hosts and non-hosts. While the extinction of species may entail losses in pathogen–host interactions and decrease the proportion of hosts infected by a pathogen (prevalence), some studies suggest the opposite pattern. Niche-based extinction, based on the species tolerance to environmental conditions, may increase prevalence of infection because the pathogen and its hosts persist, while other species go extinct. Hence, understanding prevalence of infection requires disentangling random- and niche-based extinction processes occurring simultaneously. To contribute to this exercise, we analysed the prevalence of an environmentally acquired, multi-host pathogen, Mycobacterium ulcerans (MU), in a unique dataset of 16 communities of freshwater animals, surveyed during 12 months in Akonolinga, Cameroon in equatorial Africa. Two different ecosystems were identified: rivers (lotic) and swamps and flooded areas (lentic). Increased prevalence of MU infection was correlated with niche-based extinction of aquatic host invertebrates and vertebrates in the lentic ecosystems, whereas decreased prevalence was associated with random disassembly of the lotic ecosystems. This finding suggests that random and niche-based extinction of host taxa are key to assessing the effect of local extinction of species on the ecology of environmentally acquired and multi-host pathogens.