We explore the idea that the power-law tail in the mass function of protostellar condensations and stars arises from the accretion of ambient cloud material on to a condensation, coupled with a non-uniform (exponential) distribution of accretion lifetimes. This model allows for the generation of power-law distributions in all star-forming regions, even if condensations start with a lognormal mass distribution, as may be expected from the central limit theorem, and supported by some recent numerical simulations of turbulent molecular clouds. For a condensation mass m with growth rate dm/dtproportional tom, an analytic three-parameter probability density function is derived; it resembles a lognormal at low mass and has a pure power-law high-mass tail. An approximate power-law tail is also expected for other growth laws, and we calculate the distribution for the plausible case dm/dtproportional tom(2/3). Furthermore, any single time snapshot of the masses of condensations that are still accreting (and are of varying ages) also yields a distribution with a power-law tail similar to that of the initial mass function.