Automatic analysis of pig behavior is crucial for assessing their health and welfare status in group-housed pig farms. Currently, computer vision technology has been widely applied to recognize and track pig behavior. However, these applications lack the capability for automatic behavior analysis. Additionally, execution speed is crucial for long-term tracking, as the tracking target can easily be lost due to the complex background of pig farms, uneven lighting, and the similar appearance of pigs. To tackle these challenges, we propose a lightweight multi-object tracking (MOT) and behavioral analysis method: YOLOX+BoT-SORT-Slim. Firstly, the YOLOX detector detects pig targets and recognizes the pigs’ four behaviors including “stand”, “lie”, “eat”, and “other”. Secondly, the BoT-SORT-Slim algorithm tracks the detected pigs and their behaviors at high speed. Finally, we devise a behavior automatic analysis algorithm that integrates the behavioral information and the tracking results to complete pigs’ behavior analysis. To evaluate the proposed method, we conducted experiments on 1-minute, 10-minute, and 1-hour datasets. The experimental results show that on the 1-minute public and private test sets, the proposed method achieves 6.4 and 3.6 times the frame rate (FPS) of the original algorithm, with 68.05 FPS and 71.27 FPS, respectively. It also achieves a higher-order tracking accuracy (HOTA) of 84.7 % and 78.7 %, multi-object tracking accuracy (MOTA) of 98.3 % and 97.0 %, and an identification F1 score (IDF1) of 98.4 % and 93.4 %. The proposed method obtains the best results on all test sets compared to five other MOT algorithms including DeepSORT, StrongSORT, ByteTrack, OC-SORT, and BoT-SORT. In the 10-minute and 1-hour test sets, the proposed method achieves 70.28 and 72.24, 63.3 % and 76.4 %, 94.1 % and 99.6 %, and 72.5 % and 90.2 % for FPS, HOTA, MOTA, and IDF1, respectively. In terms of behavior analysis, three types of pigs’ behavior analysis are plotted for each test video to assess their health status. The experimental results indicate that the proposed method performs excellently in behavior analysis and tracking, which can reliably monitor and manage pig behavior in real time, providing automated management technical support.