Recent developments in community models emphasize the importance of incorporating stochastic processes (e.g. ecological drift) in models of niche-structured community assembly. We constructed a finite, spatially explicit, lottery model to simulate the distribution of species in a one-dimensional landscape with an underlying gradient in environmental conditions. Our framework combines the potential for ecological drift with environmentally-mediated competition for space in a heterogeneous environment. We examined the influence of niche breadth, dispersal distances, community size (total number of individuals) and the breadth of the environmental gradient on levels of species and functional trait diversity (i.e. differences in niche optima). Three novel results emerge from this model: (1) niche differences between adjacent species (e.g. limiting similarity) increase in smaller communities, because of the interaction of competitive effects and finite population sizes; (2) immigration from a regional species pool, stochasticity and niche-assembly generate a bimodal distribution of species residence times ('transient' and 'resident') under a heterogeneous environment; and (3) the magnitude of environmental heterogeneity has a U-shaped effect on diversity, because of shifts in species richness of resident vs. transient species. These predictions illustrate the potential importance of stochastic (although not necessarily neutral) processes in community assembly. ??2005 Blackwell Publishing Ltd/CNRS.