This study aims to develop a machine learning-based tool integrated into Electronic Fiscal Devices (EFDs) to detect underpricing fraud in real time in Tanzania. The motivation for this research arises from the limitations of existing EFD systems, which rely on manual and post-audit mechanisms that are ineffective in identifying fraudulent pricing during transactions. A mixed-methods approach was employed, combining qualitative insights from tax officers with quantitative data collected from traders and buyers. A dataset of 5,000 mobile phone sales transactions collected from Arusha, Dar es Salaam, and Iringa in Tanzania, was pre-processed and used to train and evaluate multiple machine learning models, including Logistic Regression, Support Vector Machine, XGBoost, and Random Forest, using 5-fold cross-validation. The experimental results show that the Random Forest model outperformed other models, achieving an accuracy of 99.6% along with strong precision, recall, and F1-score values. To demonstrate practical applicability, the trained model was further integrated into a prototype EFD environment, where it enabled near real-time fraud detection and generated automated alerts for traders and tax authorities, with geolocation features supporting targeted enforcement. However, the dataset is limited to mobile phone transactions within selected regions of Tanzania, which may affect the generalizability of the findings. The novelty of this study lies in integrating machine learning–based price validation into EFD systems to support proactive detection of underpricing fraud at the point of transaction, thereby enhancing tax compliance and revenue protection.