Calculations of the stopping power (SP) of ion beams in solids have been based on a homogeneous electron gas scattering off a static atom and entail at least one free parameter. Here we report dynamical simulations of ions channeled in silicon. Time-dependent density-functional theory (TDDFT) is used. The calculated SPs are in excellent agreement with the observed oscillatory dependence on atomic number. TDDFT calculations for a homogeneous electron gas demonstrate that both dynamical response and nonuniformities in the electron density are essential to reproduce the data without free parameters.