The influence of magnesium doping on the optical properties, structural characteristics, and photocatalytic performance of TiO2 nanoparticles was investigated. Pure and Mg-doped TiO2 nanoparticles with varying weight percentages of magnesium were synthesized via the sol–gel method, followed by calcination at 100 °C for 12 h and annealing at 400 °C for 2 h to promote crystallization. X-ray diffraction (XRD) analyses confirmed the formation of crystalline mixed phases of anatase and rutile TiO2 nanoparticles, exhibiting their crystalline nature upon synthesis. Scanning electron microscopy (SEM) images were employed to study the morphological features of the samples, while energy dispersive spectroscopy (EDS) provided insights into their elemental composition. Photoluminescence (PL) emission spectra revealed ultraviolet (UV) to visible region emission for both pure and doped TiO2 samples. The photocatalytic activity was evaluated by monitoring the degradation of methyl orange under natural sunlight irradiation, elucidating the impact of visible light exposure. Furthermore, investigations were conducted to assess the influence of catalyst loading, initial dye concentration, and pH of the dye solution on the methyl orange removal efficiency. The 3 wt% Mg doped TiO2 exhibited 95 % of decolorization of Methyl Orange. X-ray photoelectron spectroscopy measurements was performed to verify the elemental composition and chemical valence states of each element. The scavenger test in photodegradation mechanism revealed that the main reactive species was superoxide species. The electron species resonance (ESR) measurement demonstrate that the synthesized sample shows the low spin state of Mg2+ in TiO2. The correlation between Mg doping on photocatalytic activity and crystal structure were studied. Theoretical calculations were performed to gain insights into the potential mechanism underlying the tuning of luminescent and photocatalytic properties of Mg-doped TiO2 nanoparticles, enabling a comprehensive discussion.