Traffic congestion is a critical challenge in urban areas, leading to increased travel times, pollution, and a decreased quality of life. This study addresses this issue by developing a predictive model for traffic congestion using the eXtreme Gradient Boosting (XGBoost) machine learning model, enhanced with hyperparameter optimization and detrending techniques. Key traffic parameters, including waiting times, vehicle angles, latitude, longitude, and speeds, are incorporated to improve the model's accuracy. Compared to ARIMA and LSTM models, the proposed XGBoost model significantly outperforms these approaches. LSTM exhibits much higher prediction errors. The XGBoost model, with its lowest MAE (0.007), MSE (0.008), and an accuracy of 99.5%, demonstrates superior performance and efficiency. Implemented in Python using the SUMO simulator for real-time traffic data, the proposed model showcases robust predictive capabilities, contributing to smarter urban mobility solutions and improved transportation systems. These findings underscore the effectiveness of advanced machine learning techniques in predicting traffic congestion and provide valuable insights for developing smarter urban mobility solutions. The study’s contributions aim to enhance transportation systems and improve the overall quality of urban life.