In industrial aquaculture, accurately counting fish in real-time is crucial for optimizing feeding strategies, preventing disease, and managing water quality. Current methods utilizing sensors, acoustics, machine learning, and density map regression face challenges such as high costs, invasiveness, and computational complexity. To address these limitations, we propose the YOLOv8n-MEMAGD method for accurate real-time fish counting. This method enhances YOLOv8 by incorporating the GELU activation function, MPDIoU for localization loss, and the C2f-FAM and C2f-MSCA modules into the backbone network. Additionally, the neck network is redesigned with a gather-and-distribution mechanism. Experimental results under land-based industrial aquaculture conditions demonstrate that YOLOv8n-MEMAGD achieved a mean absolute error (MAE) of 2.28 and a root mean square error (RMSE) of 2.84, even in challenging conditions such as fish overlap, aggregation, and background confounding. Compared to YOLOv8n, the proposed method increased average precision (AP50) for fish detection by 6.2 %, and significantly reduced MAE and RMSE by 61.4 % and 65.2 %, respectively, compared to CSRNet. Additionally, the method achieved a frame rate of 61 frames per second (FPS) when the number of fish ranged from 79 to 91, representing a 390.4 % increase over CSRNet. By comparing heatmaps, the proposed method demonstrates more effective detection of fish edge contours than current advanced algorithms. In conclusion, the proposed method shows promise for application in aquacultural scenarios with higher turbidity and larger number of fish.