The benthic macrofauna of the Segara Anakan lagoon, Java, Indonesia and its fringing mangroves were investigated between May 2004 and August 2006. This lagoon has been affected by various human activities for decades, in particular fishing, effluents from agriculture and industry, and illegal deforestation. In total, 163 taxa were identified, including 127 species occurring in the mangrove forest and 59 species in the subtidal. Mean density of macrobenthos was 2.5-fold higher in the central (881.8 ± 1,151.3 ind. m−2) than in the eastern mangrove site (356.3 ± 218.8 ind. m−2). Community structures differed significantly between these sites and showed a serial shift during the investigation period. Gastropods dominated the community in the central mangrove location, whereas sipunculids, polychaetes and gastropods had similar densities in the eastern site. Differences in community composition were best explained by three sediment properties: pore water salinity, δ13Corg, and Corg/N. It is suggested that small-scale heterogeneity of food availability and quality is a main factor determining the small-scale variability of the community composition. Compared to other Indo-West Pacific mangroves, species richness and densities are high. However, the dominance of specific taxa, especially of opportunistic species and the comparably low species richness in the subtidal of the lagoon may be attributed to the high sediment input by rivers in the central part and to the large-scale cutting of mangroves. Continuous tree logging will probably lead to a further spread of two fast growing understorey plants and thus to an increase of uniform swamp sites and a decrease of micro-habitats for benthic macrofauna. To our knowledge, this is the first detailed study on the spatio-temporal variation of benthic macrofauna in mangroves of Indonesia.