To evaluate the effect of thermal hydrolysis pretreatment time on the sludge anaerobic digestion system of wastewater treatment plants (WWTPs) in Daxing district, Beijing, the structure and diversity of microbial communities in primary sludge and an activated sludge anaerobic digestion system with different thermal hydrolysis pretreatment times (15 min, 30 min, and 45 min) were analyzed using Illumina MiSeq high-throughput sequencing. The results showed that the dominant groups of digested sludge were mainly distributed in Firmicutes, Cloacimonadota, Chloroflexi, and Synergistota, with W5 being the most common genus. The sum of relative abundance of the dominant phylum was greater than 60%, and W5 accounted for 20.8%-54.5%, showing a high abundance of a few dominant species. During the anaerobic digestion of thermo-hydrolyzed sludge, the relative abundance of acetogenic methanogens decreased due to high levels of volatile fatty acids (VFAs) and ammonia nitrogen (NH4+-N) concentrations, which suggested that the hydrogenophilic methanogenic pathway was more than that of the acetogenic methanogenic pathway. Correlation analysis showed that the soluble protein and pH of thermo-hydrolyzed sludge, NH4+-N of digested sludge, and thermal hydrolysis pretreatment time were the four main environmental factors affecting microbial community structure, and NH4+-N of digested sludge had the largest negative correlation with methanogens. The thermal hydrolysis pretreatment time was negatively correlated with both the Chao index and Shannon index, so longer thermal hydrolysis pretreatment time was not conducive to microbial flora during anaerobic digestion.