To address the problems of missed detection and false detection in maritime ship detection tasks under complex weather environments such as rain, fog, and low light, a maritime ship detection algorithm based on enhanced YOLOv8 under complex weather environments was proposed. Firstly, a Cross-Granularity Local Global Attention Fusion Block (CGLGAFB) was proposed, so that a refined local and global feature fusion mechanism was constructed and multi-path feature fusion strategies were combined to integrate multi-source feature information from different levels, thereby enhancing the model’s feature fusion capability as well as suppressing noise interference and information redundancy. Then, the original C2f (Faster Implementation of CSP Bottleneck with 2 convolutions) module was improved to an adaptive mixed C2f module (C2f-Adaptive Mixer Block, C2f-AMB). The target features of different scales and complex spatial structure were captured by the model more flexibly and efficiently through deep convolution branches with adaptive receptive field adjustment capability, thereby enhancing feature extraction capabilities. Finally, a Multi-scale Spatial Perception Pyramid (MSPP) module was proposed to replace SPPF(Spatial Pyramid Pooling-Fast) module, so that dilated convolutions with different dilation rates were utilized to construct multi-scale receptive fields, thereby obtaining comprehensive contextual information, and reducing the omission of key information. Experimental results on the enhanced dataset SeaShips_aug show that the proposed algorithm achieves the mAP@50 and recall of 84.7% and 79.3%, respectively, which are 2.6 and 3.9 percentage points higher than those of the baseline model YOLOv8, respectively, verifying that the proposed algorithm is more suitable for maritime ship detection tasks under complex weather environments.