Tephritidae pests severely affect the quality and safety of various melons, fruits and vegetable crops. However, many agricultural managers lack an adequate understanding of the level of pest occurrence, resulting in the misuse of pesticides, which ultimately leads to environmental pollution and economic loss. Therefore, real-time detection and counting of Tephritidae pests are important for timely pest spotting and control. This work helps quickly determine the distribution and abundance of pests in the current environment, thus providing data on pest conditions for agricultural management to optimize pesticide use. Nevertheless, the fast speed, high accuracy, and lightweight performance of real-time detection and counting are difficult to balance. To address this problem, based on the YOLOv8n model, this paper takes Bactrocera cucurbitae pests as the detection target and proposes a fast and lightweight real-time detection and individual counting model for Tephritidae pests, named YOLO_MRC. This paper introduces three key improvements: (1) Constructing a new module called Multicat into the neck network increases the focus on the detection target by incorporating an attention mechanism; (2) Reducing the original three detection heads to two and then adjusting their sizes to decrease the number of parameters in the network model; (3) Devising a novel module, C2flite, to enhance the deep feature extraction capability of the backbone network. According to the above points, this paper conducts ablation experiments to compare the performances of different models. Experiments showed that the Multicat module significantly offsets the large increase in GFLOPs and processing time caused by reducing the detection head and can further reduce the number of parameters and improve the accuracy when combined with the C2flite module. On our Bactrocera cucurbitae pest dataset, the mAP@0.5 of the YOLO_MRC model reached 99.3%. Simultaneously, as the number of parameters decreases by 63.68%, GFLOPs is reduced by 19.75%, and the processing time is shortened by 5%. To ensure the validity of the model, YOLO_MRC is compared with four excellent detection models by using manual counting results as the benchmark. YOLO_MRC achieves an average pest counting accuracy of 94%, demonstrating superior performance in terms of model size and processing time. To further explore the performance of YOLO_MRC in multiclass insect detection tasks, we choose the public dataset Pest_24_640 for comparison with four state-of-the-art models. YOLO_MRC achieves a 3.6 ms processing time and 70.4% accuracy with only a 2.4 MB model size, which demonstrates the potential of YOLO_MRC in multiclass pest detection.