Host-associated microbiomes perform many beneficial functions including resisting pathogens and training the immune system. Here, we show that amphibians developing in captivity lose substantial skin bacterial diversity, primarily due to reduced ongoing input from environmental sources. We combined studies of wild and captive amphibians with a database of over 1 000 strains that allows us to examine antifungal function of the skin microbiome. We tracked skin bacterial communities of 62 endangered boreal toads, Anaxyrus boreas, across 18 time points, four probiotic treatments, and two exposures to the lethal fungal pathogen Batrachochytrium dendrobatidis (Bd) in captivity, and compared these to 33 samples collected from wild populations at the same life stage. As the amphibians in captivity lost the Bd-inhibitory bacteria through time, the proportion of individuals exposed to Bd that became infected rose from 33% to 100% in subsequent exposures. Inoculations of the Bd-inhibitory probiotic Janthinobacterium lividum resulted in a 40% increase in survival during the second Bd challenge, indicating that the effect of microbiome depletion was reversible by restoring Bd-inhibitory bacteria. Taken together, this study highlights the functional role of ongoing environmental inputs of skin-associated bacteria in mitigating a devastating amphibian pathogen, and that long-term captivity decreases this defensive function.