Plugging and diverting stimulation technology using temporary plugging balls (PDSTB) in horizontal wells is one of the effective measures to enhance production in heterogeneous carbonate reservoirs. However, the migration and plugging mechanism of temporary plugging balls in horizontal wells remain unclear, leading to suboptimal field application. Based on the Lagrangian method, the migration and plugging models of temporary plugging balls were established. The study investigated the migration and plugging mechanism of temporary plugging balls. It analyzed the effects of parameters such as displacement on the plugging efficiency. The results show that the flow field in the perforation section is significantly affected by the displacement. Temporary plugging balls show three states of plugging: one ball plugging one shot-hole, multiple balls plugging one shot-hole, and balls remaining in the wellbore. The plugging efficiency initially increases, and then, decreases with the increase in displacement and the ball diameter. The plugging efficiency initially increases, and then, stabilizes with the increase in the viscosity of the carrying fluid and the usage ratio of balls. Plugging efficiency decreases with increasing density of balls. The greater the pressure difference at the outlet of the perforation section, the higher the plugging efficiency in the advantageous inlet section. Based on these results, the field construction of Well M was guided. The gas production was 142.66 × 104 m3/d after stimulation, and the production increase was significant. This study provides a theoretical basis for optimizing and designing the parameters of PDSTB in carbonate long horizontal wells.