The quality of drinking water is considered among the most urgent issues worldwide nowadays. Ensuring safe water for human consumption remains the highest priority, while challenges also persist in meeting the water quality needs for industrial and agricultural uses. Most of the relevant studies lack accuracy in assessing water quality. Therefore, this study aims to forecast the quality of drinking water along the Tigris River in Iraq following a new approach. A developed forecasting model that utilizes the gravitational search algorithm (GSA) was deployed. The heuristic optimization tool was utilized for the prediction of the water quality index (WQI) in the research area. Out of twelve water stations, 575 samples were gathered and used for modelling in this study. The water quality was classified according to World Health Organization (WHO) recommendations using the generally applied arithmetic method, the WQI. Based on the concentrations of eleven parameters (BOD, Ca, Cl, EC, HCO3, K, Mg, Na, NO3, pH, SO4, and TDS), the WQI for all samples was computed. The results of this study indicated that the water quality was significantly influenced. The evaluation of the applied model revealed that the GSA-based model exhibited statistically consistent performance (mean = 1.04, Standard deviation (SD) = 0.109, and Coefficient of variation (CoV) = 10.48%), indicating stable predictions compared to other models that demonstrated higher accuracy. The outcomes also showed greater variability in their results, positioning the GSA model as the preferred choice in scenarios that prioritize stability and reliability in water quality predictions.