Mg–Al co-doped ZnO (AMZO) thin films were deposited on quartz glass via sol–gel spin coating method. The structural and optical properties of Mg–Al co-doped ZnO thin films annealed at different temperatures were characterized via X-ray diffraction, Raman spectroscopy, scanning electron microscopy (SEM) with energy dispersive X-ray spectra (EDS), ultraviolet–visible–near-infrared spectroscopy, and photoluminescence spectroscopy. XRD results revealed that the films had a hexagonal wurtzite structure, and the calculated average grain size increased from 23.02 nm to 49.85 nm when the annealing temperature was increased from 500 °C to 800 °C. The change in lattice parameters was demonstrated by grain size, strain, and residual stress. The SEM images showed that the AMZO thin film surface appeared flat, and the grain size was uniformly distributed at 500 °C. When the annealing temperature was increased from 600 °C to 800 °C, the surface of the films showed larger grain sizes, numerous micropores, and some cracks. The EDS results confirmed the presence of Mg and Al elements in the AMZO thin films. Raman spectroscopy results showed that all films had E2 (high) mode, which indicates that all films had a ZnO wurtzite structure. Moreover, the optical transmittance of the AMZO thin films was over 85% in the visible region. The optical band gap of the AMZO thin films decreased from 3.348 eV to 3.304 eV when the annealing temperature was increased from 500 °C to 800 °C. The room temperature photoluminescence spectra showed an ultraviolet (UV) emission peak and a strong defect emission peak. The UV peaks of the AMZO thin films were red-shifted from 372 nm to 379 nm. In addition, the defect peaks of the AMZO thin films were blue-shifted from 598 nm to 527 nm when the annealing temperature was increased from 500 °C to 800 °C. The possible mechanisms of the defect peaks were studied.