The Agaricus genus represents the most popular edible mushroom in the world. Wheat straw often is used as the substrate for mushroom cultivation following pretreatment to degrade the lignocellulosic biomass in agricultural waste. In this study, we investigated the changes in bacterial and fungal microflora of wheat straw substrate during different phases of composting. We collected samples of the raw material (M1), phase I aerobic fermentation (F1, F2, F3), and phase II after-fermentation (AF1) for high-throughput 16S rRNA and internal transcribed spacer (ITS) sequencing to analyze the microbial diversity in the substrate during composting. Our data revealed that among the five stages, 365 operational taxonomic units (OTUs) were shared, with Firmicutes, Proteobacteria, and Actinobacteria being the predominant bacterial phyla. In addition, Thermobispora, Thermopolyspora, Ruminiclostridium, Thermobacillus, and Bacillus were the predominant genera in F3 and AF1, with the species Thermobispora bispora and Pseudoxanthomonas taiwanensis being predominant in F2. Both principal component analysis (PCA) and nonmetric multidimensional scaling (NMDS) plots showed that the bacterial communities of five stages could be distinguished from each other based on their composting time. The Shannon and Simpson indexes of F2 were lower than M1 (P < 0.05), and the clustering dendrogram showed that the bacterial communities in AF1 were similar to F3, with Micromonosporaceae, Streptosporaceae, Thermomonosporaceae, and Vulgatibacteraceae representing the differential bacterial families by linear discriminant analysis with effect size (LEfSe) analysis. The analysis of fungal communities showed that 384 OTUs were common among the five stages, with 1054 and 454 OTUs unique to M1 and AF1, respectively. Ascomycota and Basidiomycota were the two predominant phyla in all stages, and Chytridiomycota was predominant in F2, F3, and AF1 stages. PCA and NMDS plots showed that the clusters of F2 and AF1 were more dispersed than the other stages. No differences were observed in alpha diversity between the stages, and samples of F1, F2, and F3 were closer to AF1 in the clustering dendrogram. By LEfSe analysis, Mycothermus thermophilus, Gonapodya polymorpha, and Phaeophleospora_eugeniae were identified as the predominant fungal species in AF1.