In contrast to its bulk crystal, the FeSe thin film or layer exhibits better superconductivity performance, which recently attracted much interest in its fundamental research as well as in potential applications around the world. In the present work, tuning superconductivity in FeSe thin films was achieved by magnesium-doping technique. Tc is significantly enhanced from 10.7 K in pure FeSe films to 13.4 K in optimized Mg-doped ones, which is approximately 1.5 times higher than that of bulk crystals. This is the first time achieving the enhancement of superconducting transition temperature in FeSe thin films with practical thickness (120 nm) via a simple Mg-doping process. Moreover, these Mg-doped FeSe films are quite stable in atmosphere with Hc2 up to 32.7 T and Tc(zero) up to 12 K, respectively, implying their outstanding potential for practical applications in high magnetic fields. It was found that Mg enters the matrix of FeSe lattice, and does not react with FeSe forming any other secondary phase. Actually, Mg first occupies Fe-vacancies, and then substitutes for some Fe in the FeSe crystal lattices when Fe-vacancies are fully filled. Simultaneously, external Mg-doping introduces sufficient electron doping and induces the variation of electron carrier concentration according to Hall coefficient measurements. This is responsible for the evolution of superconducting performance in FeSe thin films. Our results provide a new strategy to improve the superconductivity of 11 type Fe-based superconductors and will help us to understand the intrinsic mechanism of this unconventional superconducting system.