Edge computing has gained significance in processing data near the source. However, its distributed and resource-constrained nature is prone to security challenges, particularly the Man-in-the-Middle (MitM) attacks. In response to these challenges, this study proposes an optimized Machine Learning model designed for edge computing, to enhance MitM attack detection. The research addresses security vulnerabilities in evolving technologies to harden security measures in resource-constrained environments, particularly in Africa and other developing regions. The proposed optimised model provides practical solutions to address security challenges unique to under-resourced regions by employing a more robust digital infrastructure. The optimized proposed model was compared to the Decision Tree and Random Forest algorithms to evaluate its effectiveness. The optimized model achieved the best performance, in accuracy, precision, recall, and F1 score, which demonstrates its effectiveness in addressing MitM attacks in edge computing. The study contributes to the mitigation of MitM attacks and underscores the significance of optimization in resource-constrained environments. In future, the research should further explore and enhance the security mechanisms for the dynamic and resource-constrained nature of developing countries. It should facilitate reliable and resilient operation of edge systems in the face of evolving security challenges. As edge computing continues to evolve, our findings contribute to the design of robust security mechanisms for, emerging threats in dynamic networks.