During the development cycle of software projects, numerous defects and challenges have been identified, leading to prolonged project durations and escalated costs. As a result, both product delivery and defect tracking have become increasingly complex, expensive, and time-consuming. Recognizing the challenge of identifying every software defect, it is crucial to foresee potential consequences and strive for the production of high-quality products. The goal of software defect prediction (SDP) is to identify problematic locations within software code. This study presents the first experimental investigation utilizing the turbulent flow of water optimization (TFWO) in conjunction with the adaptive neuro-fuzzy inference system (ANFIS) to enhance SDP. The TFWO_ANFIS model is designed to address the uncertainties present in software features and predict defects with feasible accuracy. Data are divided randomly at the beginning of the model into training and testing sets to avoid the local optima and over-fitting issues. By applying the TFWO approach, it adjusts the ANFIS parameters during the SDP process. The proposed model, TFWO_ANFIS, outperforms other optimization algorithms commonly used in SDP, such as particle swarm optimization (PSO), gray wolf optimization (GWO), differential evolution (DE), ant colony optimization (ACO), standard ANFIS, and genetic algorithm (GA). This superiority is demonstrated through various evaluation metrics for four datasets, including standard deviation (SD) scores (0.3307, 0.2885, 0.3205, and 0.2929), mean square error (MSE) scores (0.1091, 0.0770, 0.1026, and 0.0850), root-mean-square error (RMSE) scores (0.3303, 0.2776, 0.3203, and 0.2926), mean bias error (MBE) scores (0.1281, 0.0860, 0.0931, and 0.2310), and accuracy scores (87.3%, 90.2%, 85.8%, and 89.2%), respectively, for the datasets KC2, PC3, KC1, and PC4. These datasets with different instances and features are obtained from an open platform called OPENML. Additionally, multiple evaluation metrics such as precision, sensitivity, confusion matrices, and specificity are employed to assess the model’s performance.