Abiotic and biotic factors structure species assembly in ecosystems both horizontally and vertically. However, the way community composition changes along comparable horizontal and vertical distances in complex three-dimensional habitats, and the factors driving these patterns, remain poorly understood. By sampling ant assemblages at comparable vertical and horizontal spatial scales in a tropical rain forest, we compared observed patterns with those predicted according to environmental filtering by microclimate and microhabitat structure. We found that although dissimilarity between ant assemblages increased with vertical distance, the dissimilarity was higher horizontally but was independent of distance. The pronounced horizontal and vertical structuring of ant assemblages across short distances is likely explained by a combination of microclimate and microhabitat connectivity. Our results demonstrate the importance of considering three-dimensional spatial variation in local assemblages and reveal how highly diverse communities can be supported by complex habitats.