Cordyceps sensu lato is a complex fungus‐larva symbiote, and its distribution is affected by the geography, climate, soil environment, and cohabitating microorganisms. However, despite the fact Cordyceps militaris and Ophiocordyceps highlandensis are different species, they coexist in the Pinus armandi forest of Dashao in Songming County, Yunnan, China. We explored the microbial compositions and soil metabolism inhabited by C. militaris and O. highlandensis using high‐throughput sequencing and nontargeted metabonomics. The results indicated that the bacterial and fungal compositions in the soil microhabitat communities of C. militaris, O. highlandensis, and null Cordyceps group were similar. However, the community compositions in the fruiting bodies of C. militaris and O. highlandensis were different. The dominant phylum Ascomycota and dominant genus Cordyceps were detected in the fruiting body of C. militaris. Except for Ascomycota, the dominant phylum Chytridiomycota and dominant genera Ophiocordyceps, Unclassified_k__Hypocreales, Circinotrichum, Cladosporium, and Unclassified_k__chytridiomycetesg were detected in the fruiting body of O. highlandensis. The plant probiotic bacteria Phyllobacterium was detected in the fruiting body of C. militaris. The growth‐promoting bacteria Pseudomonas was detected in the fruiting body of O. highlandensis. Soil metabolism analysis revealed that pathways associated with amino acid metabolism was significantly enriched in O. highlandensis. Correlation analysis of bacterial diversity and soil metabolites revealed that the relative abundances of bacterial operational taxonomic units and the relative contents of metabolites were consistent. Our results provide insights into the microbial diversity and soil metabolism of naturally coexisting C. militaris and O. highlandensis.