Selective harmonic elimination (SHE) is an efficient method to eliminate low-order selected harmonics. However, due to nonlinearity in the problems, many optimization techniques give unsatisfied performances in finding optimum switching angles for the SHE. This paper proposes a modified moth-flame optimization algorithm to eliminate selective harmonics in cascaded multilevel inverters. The optimization algorithm is employed to find sets of optimum switching angles for cascaded 5-level, 7-level, and 9-level inverters. The results have shown that modified moth-flame optimization is beneficial in finding optimum switching angles. It performs better than moth-flame optimization (MFO) and differential evolution (DE) algorithms. The optimum switching angles are applied to generate switching pulses for a cascaded 9-level inverter to demonstrate the algorithm’s accuracy. As a result, the low-order harmonics are entirely removed from the ac output voltage of the inverter.