This study introduces a novel approach to synthesizing magnesium oxide (MgO) nanoparticles through the use of Ocimum sanctum (tulsi seed) extract combined with the thermal polymerization of MgO-doped graphitic carbon nitride (MgCN) nanocomposites. The nanocomposites were prepared at varying MgO concentrations (0.5 mM, 1.0 mM, 1.5 mM, and 2.0 mM) to optimize their properties. Comprehensive characterization of the synthesized MgO nanoparticles and MgCN nanocomposites was conducted using advanced analytical techniques, including UV-Vis spectroscopy, X-ray diffraction (XRD), scanning electron microscopy with energy dispersive X-ray mapping (SEM-EDX), Fourier-transform infrared spectroscopy (FTIR), and thermogravimetric analysis (TGA). The MgCN nanocomposite with 1.5 mM MgO demonstrated a high surface area of 98.287 m2 g-1, as determined by Brunauer-Emmett-Teller (BET) analysis. X-ray photoelectron spectroscopy (XPS) confirmed the presence of carbon and nitrogen elements, validating the integration of MgO into the nanocomposite matrix. High-resolution transmission electron microscopy (HRTEM) images depicted planar, stacked, and wrinkled structures characteristic of a graphitic-like material. Consistent with a Z-scheme heterojunction, the MgCN (1.5 mM) sample exhibited an enhanced morphology, increased surface area, improved visible light absorption, and reduced band gap. This particular nanocomposite displayed remarkable adsorption and photocatalytic degradation capabilities, achieving up to 98% removal of methylene blue and 54% removal of tetracycline antibiotics. Furthermore, it showed significant antibacterial activity against Escherichia coli. Notably, the MgCN (1.5 mM) nanocomposite maintained its performance over four cycles, underscoring its potential for sustained application in wastewater treatment and the elimination of organic contaminants. The scavenging activity of the nanocomposites was also explored, revealing additional environmental benefits. This research highlights a promising pathway for developing eco-friendly nanocomposites with robust capabilities in water purification and pollution control.