During the developmental stages, eggplants are susceptible to diseases, which can impact crop yields and farmers’ economic returns. Therefore, timely and effective detection of eggplant diseases is crucial. Deep learning-based object detection algorithms can automatically extract features from images of eggplants affected by diseases. However, eggplant disease images captured in complex farmland environments present challenges such as varying disease sizes, occlusion, overlap, and small target detection, making it difficult for existing deep-learning models to achieve satisfactory detection performance. To address this challenge, this study proposed an optimized eggplant disease detection algorithm, YOLOv8-E, based on You Only Look Once version 8 nano (YOLOv8n). Firstly, we integrate switchable atrous convolution (SAConv) into the C2f module to design the C2f_SAConv module, replacing some of the C2f modules in the backbone network of YOLOv8n, enabling our proposed algorithm to better extract eggplant disease features. Secondly, to facilitate the deployment of the detection model on mobile devices, we reconstruct the Neck network of YOLOv8n using the SlimNeck module, making the model lighter. Additionally, to tackle the issue of missing small targets, we embed the large separable kernel attention (LSKA) module within SlimNeck, enhancing the model’s attention to fine-grained information. Lastly, we combined intersection over union with auxiliary bounding box (Inner-IoU) and minimum point distance intersection over union (MPDIoU), introducing the Inner-MPDIoU loss to speed up convergence of the model and raise detection precision of overlapped and occluded targets. Ablation studies demonstrated that, compared to YOLOv8n, the mean average precision (mAP) and F1 score of YOLOv8-E reached 79.4% and 75.7%, respectively, which obtained a 5.5% increment and a 4.5% increase, while also reducing the model size and computational complexity. Furthermore, YOLOv8-E achieved higher detection performance than other mainstream algorithms. YOLOv8-E exhibits significant potential for practical application in eggplant disease detection.