In multiband superconductors, multiple collective modes exist associated with the multiple order parameters. Oscillations of the amplitude and the relative phase of the order parameters are called Higgs and Leggett modes, respectively. Recently, it has been suggested that nonmagnetic impurity scattering would enhance nonlinear coupling between the Higgs mode and an electromagnetic wave with a frequency located in the superconducting gap region, while its effect on the Leggett mode is still unresolved. Here, we theoretically investigated the nonlinear optical response of multiband Bardeen-Cooper-Schrieffer-type superconductors in the presence of nonmagnetic impurities with a density matrix approach extending the Mattis-Bardeen model of linear response. We found that the drastic enhancement of nonlinear optical response due to the nonmagnetic impurity scattering occurs only for the Higgs modes and not for the Leggett mode. As a result, both the light-induced dynamics of the superconducting gaps and the resulting third-harmonic generation are dominated by the Higgs modes. We also examined the role of quasiparticle excitations to find that they give the subdominant contribution to the third-harmonic generation.