posing a significant challenge to network performance and reliability. In a gray hole attack, a malicious node selectively drops packets while forwarding others, leading to increased packet loss and latency. This paper presents a novel Gray Hole Prevention algorithm designed to detect and mitigate the effects of such attacks, thereby enhancing the security and efficiency of MANETs. The proposed algorithm integrates existing techniques, specifically the Secure Detection Prevention and Elimination Gray Hole (SDPEGH) approach, with proactive measures to improve detection accuracy and minimize the risk of blacklisting legitimate nodes. Extensive simulations were conducted using the NS-2 simulation tool, comparing the performance of the proposed algorithm against traditional methods. The results demonstrate a significant improvement in network performance, with the GRAY-HP algorithm achieving a PDR of 92%, compared to 78% for the SDPEGH algorithm, representing an increase of 18%. Additionally, the throughput improved by 25%, reaching 85 kbps, while the energy consumption was reduced by 15%, indicating a more efficient use of resources. The routing overhead was also minimized by 20%, showcasing the algorithm's effectiveness in maintaining network stability. This research contributes to the field of network security by providing a robust solution to gray hole attacks, thereby enhancing the reliability and performance of MANETs. The findings underscore the importance of proactive security measures in dynamic and decentralized environments, paving the way for future advancements in secure communication protocols for mobile networks.