Aim It is a central issue in ecology and biogeography to understand what governs community assembly and the maintenance of biodiversity in tropical rain forest ecosystems. A key question is the relative importance of environmental species sorting (niche assembly) and dispersal limitation (dispersal assembly), which we investigate using a large dataset from diverse palm communities. Location Lowland rain forest, western Amazon River Basin, Peru. Methods We inventoried palm communities, registering all palm individuals and recording environmental conditions in 149 transects of 5m×500m. We used ordination, Mantel tests and indicator species analysis (ISA) to assess compositional patterns, species responses to geographical location and environmental factors. Mantel tests were used to assess the relative importance of geographical distance (as a proxy for dispersal limitation) and environmental differences as possible drivers of dissimilarity in palm species composition. We repeated the Mantel tests for subsets of species that differ in traits of likely importance for habitat specialization and dispersal (height and range size). Results We found a strong relationship between compositional dissimilarity and environmental distance and a weaker but also significant relationship between compositional dissimilarity and geographical distance. Consistent with expectations, relationships with environmental and geographical distance were stronger for understorey species than for canopy species. Geographical distance had a higher correlation with compositional dissimilarity for small-ranged species compared with large-ranged species, whereas the opposite was true for environmental distance. The main environmental correlates were inundation and soil nutrient levels. Main conclusions The assembly of palm communities in the western Amazon appears to be driven primarily by species sorting according to hydrology and soil, but with dispersal limitation also playing an important role. The importance of environmental characteristics and geographical distance varies depending on plant height and geographical range size in agreement with functional predictions, increasing our confidence in the inferred assembly mechanisms.