During the formation of intermediate-scale cosmic structures (groups and clusters of galaxies), dynamical friction is produced by small-scale substructure which is abundantly generated in most of the hierarchical clustering scenarios (e.g., cold dark matter, purely baryonic dark matter, and hybrid models). In this paper we study the effects induced by dynamical friction on the collapse of shells of matter falling onto the central regions of groups and clusters of galaxies. We find that the collapse of the shells is modified with respect to the homogeneous case: specifically, it is slowed down by the frictional force, so that the collapse time T(c) increases steeply with the distance r from the center of the system and becomes larger than the Hubble time for shells having overdensities delta(typ) less than or similar to 10(-2). As a consequence, the total mass that can be accreted on time-scales less than or similar to H-1 by the central regions of the structure is lower than in the uniform, homogeneous accretion model of Gunn & Gott (1972). We perform a detailed study of the dependence of T(c) on various initial parameters of the shell dynamics, and we compute the effect of this modified shell dynamics on the evolution of the mass accreted by initially collapsed clumps. We also find that dynamical friction affects the statistics of the mass distribution, N(M, t), of those clusters of galaxies that might have undergone a substantial secondary infall.