Insufficient carbon sources in low-carbon wastewater have consistently hindered nitrogen removal performance. This work utilized slurry after anaerobic digestion as an additional carbon source, and the optimal hydraulic retention time (HRT) parameters were obtained through adjustment. The findings revealed that, under HRT conditions of 24–12 h, the discharge standards of wastewater treatment plants (WWTPs) could be met. It had been proven that HRT 12 h was the more cost-effective parameter for application in WWTPs, and the removal efficiencies for COD, NH4+-N, NO3–-N, and TN reached impressive levels of 82.43%, 95.24%, 77.49%, and 86.70%, respectively. However, the HRT 6 h struggled to achieve efficient wastewater treatment. Mechanistic analysis demonstrated that shortening the HRT resulted in considerably higher microbial richness, diversity, and evenness, causing notable shifts in microbial community structure. Additionally, a shortened HRT reduced the enrichment abundance of key bacterial phyla (Proteobacteria, Bacteroidetes) and genera (Hydrogenophaga, Filimonas, Meganema) that played an important role in nitrogen and organic matter removal. Furthermore, a shortened HRT increased hydraulic shear forces, impeding the enrichment of carbon and nitrogen metabolism pathways, and reducing the abundance of essential genes associated with glycolysis (HK, pfkA, FBA, GAPDH) and nitrogen metabolism processes (narG, narH, narI, norB, nirS, nosZ). It was noteworthy that the microbial community under the HRT 6 h condition carried the highest risk of microbial pathogenicity. This work revealed the optimal parameters, and carbon and nitrogen metabolism mechanism of wastewater treatment systems with slurry as a carbon source for the first time, and provided novel ideas and insights for low-carbon wastewater treatment.