The distribution of the induced electric field (E-field) during transcranial magnetic stimulation (TMS) depends on the individual anatomical structure of the brain as well as coil positioning. Inappropriate stimulation may degrade the efficacy of TMS or even induce adverse effects. Therefore, optimizing the E-field according to individual anatomy and clinical need has become a research focus. In this paper, particle swarm optimization (PSO) was applied for the first time to the positioning of TMS coils with anatomical head models. We discuss the parameters of the PSO algorithm, which were optimized to achieve a reasonable convergence time suitable for in-time treatment planning. The optimizer improved the distribution of the induced E-field strength at the dedicated cortical region, with a mean value of 48.31% compared with that from the conventional treatment position. The optimization terminated after 4–11 iterations for 13 head models. The applicability and performance of the optimizer for a large population are discussed in terms of cortical complexity. This study could benefit not only clinics but also research on brain modulation.