Background. Assemblage responses to environmental gradients are key to understand the general principles behind the assembly and functioning of communities. The spatial and temporally uneven distribution of water availability in drylands creates strong aridity gradients. While the effects of spatial variations of aridity are relatively well known, the influence of the highly-unpredictable seasonal and interannual precipitations on dryland communities has been seldom addressed. Aims. Here we study the seasonal and interannual responses of dung beetle (Coleoptera, Scarabaeidae) communities to the variations of water availability along an arid to semiarid region of the Mediterranean. Methods. We surveyed a 400 km linear transect along a strong aridity gradient from the Mediterranean coast to the Sahara (Eastern Morocco), during four sampling campaigns: two in the wet season and two in the dry season. We measured richness, abundance and evenness. Variations in community composition between sites, seasons and years were assessed through beta diversity partitioning of dissimiliarity metrics based on species occurrences and abundances. The effects of climate, soil, vegetation and dung availability were evaluated using Spearman-Rank Correlations, GLMs and partial least-squares generalized lineal regressions for community structure, and NMDS, PERMANOVA and dbRDA-based variation partitioning for compositional variations. Results. Dung beetle abundance and richness showed large seasonal variations, but remained relatively similar between years. Increasing aridity resulted in decreasing species richness and an ordered replacement of species, namely the substitution of the trophically diverse Mediterranean fauna by saprophagous and generalist species both in space towards the Sahara and seasonally in the dry season. Indeed, aridity and its interaction with season and year were the strongest correlates of variations in richness and composition. Discussion. Our study shows that aridity determines composition in dung beetle communities, filtering species both in space and time. Besides the expected decrease in richness, such environmental filtering promotes a functional shift to generalist and saprophagous species in arid conditions, probably related to changes in resource quality along the transect and through the year. Our results highlight the importance of considering the effects of the highly-unpredictable seasonal and interannual variations in precipitation when studying dryland communities.