This work explores the enhancement of dye-sensitized solar cells (DSSCs) by using magnesium oxide nanoparticles (MgO NPs) that have been green-synthesized, with carambola extract acting as a natural dye sensitizer. Green synthesis minimizes the negative effects of traditional synthesis methods on the environment by providing a sustainable and ecologically friendly way to produce MgO NPs. To increase their effectiveness in DSSC applications, the synthesized nanoparticles underwent optimization. The morphology and size distribution of MgO NPs were characterized by scanning electron microscopy (SEM), which revealed spherical forms with a consistent size distribution. The crystalline nature of the MgO NPs was verified by X-ray diffraction (XRD), which revealed distinctive peaks that correspond to the bulk MgO crystal planes. A band gap of 3.5 eV, appropriate for UV region absorption, was found using UV–visible spectroscopy. FT-IR (Fourier-transform infrared) spectroscopy revealed information about their molecular compositions. Positive electronic characteristics, such as a negative total energy change (ΔE_T) and a high electrophilicity index (ω), which indicates effective charge transfer, were found through computational analysis. The light harvesting efficiency (LHE) value of 0.00459 signifies optimal light absorption capability by the dye molecule. The outcomes show that MgO NPs that have undergone green synthesis have the potential to be efficient and stable sensitizers for DSSCs. In addition to highlighting the significance of green synthesis techniques in nanomaterial research for renewable energy applications, this work advances the development of efficient and sustainable solar energy systems.