Moth Flame Optimization (MFO) is a swarm intelligence algorithm inspired by the nocturnal flight mode of moths, and it has been widely used in various fields due to its simple structure and high optimization efficiency. Nonetheless, a notable limitation is its susceptibility to local optimality because of the absence of a well-balanced exploitation and exploration phase. Hence, this paper introduces a novel enhanced MFO algorithm (BWEMFO) designed to improve algorithmic performance. This improvement is achieved by incorporating a Gaussian barebone mechanism, a wormhole strategy, and an elimination strategy into the MFO. To assess the effectiveness of BWEMFO, a series of comparison experiments is conducted, comparing it against conventional metaheuristic algorithms, advanced metaheuristic algorithms, and various MFO variants. The experimental results reveal a significant enhancement in both the convergence speed and the capability to escape local optima with the implementation of BWEMFO. The scalability of the algorithm is confirmed through benchmark functions. Employing BWEMFO, we optimize the kernel parameters of the kernel-limit learning machine, thereby crafting the BWEMFO-KELM methodology for medical diagnosis and prediction. Subsequently, BWEMFO-KELM undergoes diagnostic and predictive experimentation on three distinct medical datasets: the breast cancer dataset, colorectal cancer datasets, and mammographic dataset. Through comparative analysis against five alternative machine learning methodologies across four evaluation metrics, our experimental findings evince the superior diagnostic accuracy and reliability of the proposed BWEMFO-KELM model.