Space light-fiber coupling technology converts spatially transmitted beams into fiber-optic transmissions, facilitating free-space optical communication, and fiber laser radar systems for signal processing in optical fibers. However, it is very difficult to accomplish precise alignment between the spatial beams and the fiber with micron level. In this paper, particle swarm optimization is applied to achieve two-dimensional auto-alignment between the spatial beams and the fiber. The theory proves that when the dimension takes 2, the number of groups is 10, the inertia weight is 0.4~0.8 and the number of iteration does not exceed 100, the particle swarm optimization can converge to the maximum coupling power, and the greater the weight of the inertia, the slower the convergence speed, the larger the search area. If the inertia weight decreases linearly with the number of iterations, the spatial light-fiber coupling auto-alignment function can be quickly completed while searching the alignment space in a wide range.