The safety of maritime environments in context with effective and secure wireless communication networks is required for ships, coastal stations, and maritime authorities. The dynamic nature of marine environments, where ships traverse vast and unpredictable expanses of oceans and seas, presents big challenges to safety and risk management. Wireless communication technology is widely employed in maritime activities for communication via ocean networks and underwater wireless sensor networks (UWSNs). Maintaining the safety of the maritime environment, effective anomaly detection, prompt risk mitigation, and real-time communication becomes more difficult due to its dynamic nature. International trade and transportation are facilitated by the maritime industry. In addition to protecting lives and averting environmental disasters, maritime safety is important for maintaining the effectiveness and dependability of shipping routes. To handle the intricacies of maritime safety, this work proposes a novel preventive framework for anomaly detection and risk management in Maritime Wireless Communications (MWC). The proposed framework is based on edge computing and machine learning models. The framework makes use of edge computing technology to process data locally, lowering latency and enabling real-time communication in maritime environments. A proactive safety approach has been adopted to ensure the wellbeing of seafarers, safeguard vessels, and protect the marine environment. As maritime cybersecurity threats continue to evolve, the proposed research aims to enhance the cybersecurity posture of MWC. The framework will incorporate measures to detect and respond to potential cyber threats, ensuring the integrity and security of communication channels under international maritime cybersecurity standards. The proposed anomaly detection framework incorporates machine learning models such as Long Short-Term Memory (LSTM) and Isolation Forests (IF). The proposed framework also places a strong emphasis on preventative safety measures, including cybersecurity safeguards to protect communication channels in the constantly changing digital marine operations environment. To demonstrate the effectiveness of the proposed framework, the experiments were performed based on a publicly available dataset and implemented in the context of marine communications. The results show significant accuracy as well as high precision, recall, and F1-score metrics generated by the LSTM and IF models. The results highlight that the proposed framework can detect anomalies and potential threats in real-time marine communications.INDEX TERMS Machine learning; intelligent systems; sustainable navigation, autonomous vessels, ship safety management systems; maritime shipping and satellite technology; sensing and communication in maritime; automatic identification system; edge computing, prevention of ship accidents.