Solar-blind photodetectors based on gallium oxide (Ga2O3) have shown possibilities in optical imaging, spatial communication, and other fields. The high oxygen vacancy (VO) content inherent in Ga2O3 film would inevitably result in poor photoelectric detection capability. This work suggests using a codoping for reducing VO concentrations in Ga2O3 films. In a N2O atmosphere, magnesium and nitrogen codoped gallium oxide (Mg–N:Ga2O3) films were grown using the pulsed laser deposition (PLD) technique on (0001) sapphire substrates. It is possible to produce codoped Ga2O3 thin films with low oxygen vacancy density and high crystalline quality by thoroughly examining and optimizing preparation conditions. Metal-semiconductor-metal (MSM) photodetectors were constructed using both pristine and Mg–N codoped Ga2O3 thin films as the active layer. The photodetector with a codoped active layer outperforms those with pristine Ga2O3, with a quick decay time of 20 ms, a high sensitivity of 2.61 × 105, and a high responsivity of 0.191 A/W under 254 nm UV light irradiation, highlighting the significance of the VO concentration decrease in the application of Ga2O3-based solar-blind photodetectors.