Food price volatility poses significant challenges to food security, poverty reduction, and economic planning in Nigeria. In response to these concerns, this study applies advanced machine learning techniques Long Short-Term Memory (LSTM) networks and Extreme Gradient Boosting (XGBoost) to forecast food prices using data from the World Food Programme spanning 2002 to 2024. Comprehensive data preprocessing steps were undertaken, including normalization and feature engineering, with the integration of external macroeconomic indicators such as inflation rates and fuel prices to enrich the models. Model performance was evaluated using standard metrics: Mean Squared Error (MSE), Root Mean Squared Error (RMSE), Mean Absolute Error (MAE), and the coefficient of determination (R²).The results demonstrate that the XG Boost model outperformed the LSTM network across all evaluation criteria. XGBoost achieved a lower RMSE of ₦62.94 and a lower MAE of ₦39.39, compared to LSTM’s RMSE of ₦84.27 and MAE of ₦49.20. Moreover, XGBoost attained a higher R² value of 0.91 versus LSTM’s 0.83, indicating greater predictive accuracy and better explanatory power. Both models successfully captured major historical price disruptions associated with the 2008–2010 global financial crisis and the COVID-19 pandemic, while a period of relative price stability was observed between 2016 and 2018.The findings highlight the value of machine learning models particularly XGBoost as effective tools for enhancing food price forecasting and supporting proactive, data-driven food security interventions. Future research could further improve predictive accuracy by incorporating real-time satellite imagery, weather variables, and broader macroeconomic indicators into forecasting frameworks.