Keeping healthy status is the primary condition in endangered captive breeding of alpine musk deer (Moschus chrysogaster, AMD), and that captive breeding program is beneficial to the ex-situ conservation and wild population recovery of musk deer. Therefore, regulating the health status of captive musk deer is the premise of musk deer resource utilization. Meanwhile, gut microbiota is essential for host health, survival and environmental adaptation. However, the changes of feeding environment and food affected the composition and function of gut microbiota in musk deer. Here, 16S rRNA was used to reveal the composition and function variations between wild and captive AMD. Wild AMD had higher alpha diversity of gut microbiota, with higher relative abundance of phylum Firmicutes, and dominant genera UCG-005, Christensenellaceae R7 group, Monoglobus, Ruminococcus, and Roseburia, which conducive to the wild AMD more effective absorption and utilization of nutrients, stability of intestinal microecology, and adaption to complex natural environment. Captive individuals had higher metabolic functions, with higher relative abundance of phylum Bacteroidetes, and dominant genera Bacteroides, Rikenellaceae RC9 gut group, NK4A214 group and Alistipes, which contributed to the metabolic activities of various nutrients. Furthermore, 11 potential opportunistic pathogens in captive AMD were higher than those in wild AMD, with higher enrichment of disease-related functions. Compared with wild populations, captive musk deer had a higher risk of intestinal diseases. The results can provide a theoretical basis for healthy breeding of musk deer, and a guidance for evaluating the health status of wild release and reintroduction of musk deer.