An explicit expression for the quadratic density-response function of a many-electron system is obtained in the framework of the time-dependent density-functional theory, in terms of the linear and quadratic density-response functions of noninteracting Kohn-Sham electrons and functional derivatives of the time-dependent exchange-correlation potential. This is used to evaluate the quadratic stopping power of a homogeneous electron gas for slow ions, which is demonstrated to be equivalent to that obtained up to second order in the ion charge in the framework of a fully nonlinear scattering approach. Numerical calculations are reported, thereby exploring the range of validity of quadratic-response theory.