The lack of understanding regarding how endophytic fungi affect the accumulation of metabolites has hindered the comprehension of the influencing factors on the accumulation of active components in E. sinica. This study investigates the accumulation characteristics of secondary metabolites, the composition and succession patterns of endophytic fungi, and their correlations in the roots or stems of E. sinica with five different growth years. The results showed that the accumulations of some special compounds such as ephedrine A-D and flavonol in the roots, as well as the content of methylephedrine, pseudoephedrine, and flavonoid compounds in the stems exhibited unique variations depending on the duration of cultivation. The composition and structure of endophytic fungi in roots or stems also undergo regular succession over time, and the fungal composition and diversity of stems were more complex and higher than those of roots. Significant or highly significant correlations were observed between the accumulation of most compounds and specific fungi. Aporospora was a key genus influencing numerous metabolites. Specifically, root alkaloids showed significant or highly significant negative correlations with fungi including A. gracilis, Pleosporales sp., and Zopfiella sp., whereas A. gracilis was positively correlated with flavonoids. In the stems, phenylpropyl alkaloids were significantly correlated with thirteen fungi, among which Aporospora sp. was highly significant negative correlation with ephedrine and highly significant negative correlation with pseudoephedrine. These results contribute to a better understanding of the factors associated with metabolite accumulation in E. sinica and provide an empirical evidence for improving its quality.