To enhance the quality of life and ensure sustainability in crowded cities, safe management of drinking water using cutting-edge technologies is a priority. This study developed an intelligent early warning system (EWS) for alarming and controlling risks from bacteria and disinfection byproducts in a drinking water distribution system (DWDS), named BARCS (Bacterial Risk Controlling System). BARCS adopts an artificial intelligence (AI) approach to data-driven prediction and considers total chlorine (TCl) concentration as the pivot indicator for risk identification and control. First, the machine learning-based AI model in BARCS can provide a reliable prediction of TCl concentration in a DWDS, with an average R2 of 0.64 for the validation set, while offering great flexibility for BARCS to adapt to various conditions. Second, TCl concentration was proven to be a good indicator of bacterial risk in a DWDS, as well as a cost-effective surrogate variable to assess disinfection byproduct risk. Third, the robustness analysis demonstrates that with state-of-the-art water quality monitoring technologies, online implementation of BARCS in real-world settings is feasible. Overall, BARCS represents a promising solution to the safe management of drinking water in future smart cities. HIGHLIGHTS BARCS predicts and regulates bacterial risk in pipelines.; TCl prediction module harvests an average R2 of 0.64 for the validation set.; The relationship between TCl and CFU is quantified.; Online implementation of BARCS in real-world settings is feasible.;