Anisodus tanguticus is a valuable plant for extracting tropane alkaloids. However, the mechanisms by which plant microbiome mediate the accumulation of tropane alkaloids in Anisodus tanguticus are still not well understood. In this study, we collected 55 wild Anisodus tanguticus populations on the Tibetan Plateau and the tropane alkaloids content, and root-related bacteria and fungi diversity were analyzed using HPLC and 16 s rDNA and ITS sequencing. The results showed that tropane alkaloids content has obvious geographical distribution characteristics. Anisodine content had a significant positive correlation with latitude, while anisodamine and atropine content had a significant negative correlation with latitude. Variation partition analysis (VPA) showed that root endophytes play a significant role in promoting tropane alkaloid production in Anisodus tanguticus roots. The root endophytes alone explained 14% of the variation, which was the largest contributor. Soil properties variables could independently explain 5% of the variation, and climate variables could explain 1% of the variation. Of these, endophytic fungi alone accounted for 11%, while bacteria explained only 5%. Random forests and Mantel test showed that different regionally enriched endophytic fungi have a greater impact on the accumulation of tropane alkaloids than the whole endophytic fungi. Richness and relative abundance of enriched endophytic fungi in Hengduan-Qilian Mountains (HQ) group has a significant positive correlation with anisodine content, while richness and relative abundance of enriched endophytic fungi in Himalayas-Hengduan Mountains (HH) group has a significant positive correlation with anisodamine and atropine content. And, these enriched endophytic fungi have high network connectivity and distributed in separate network modules. This study further confirmed that endophytes were closely related to tropane alkaloids accumulation in Anisodus tanguticus and contribute to promote sustainable development, cultivation, and precision medicine of Anisodus tanguticus.