Macrofauna play a key role in the functioning of mangrove ecosystems. Nevertheless, our understanding of the diversity and functional structure of macrofaunal communities across different habitats in the mangrove forests of the Persian Gulf is limited. In this study, we investigated species diversity and biological trait patterns of macrofauna in different mangrove-associated habitats, i.e., encompassing actual mangrove forests, and adjacent Beaches and Creeks, which exhibit different levels of habitat heterogeneity. Samples were collected from the different habitats in five different locations, over four seasons. A total of 122 macrofauna taxa were identified. The diversity of species was higher in summer than in winter. In the Beach habitats, species diversity showed an increasing trend from land toward the mangrove, whereas in Creek habitats diversity decreased from the Creek toward the mangrove. Multivariate community analysis showed differences in the distribution of abundant species and biological traits across all habitats. Deposit-feeding, crawlers, medium-size, and free-living were the dominant trait modalities in all habitats. The similarities within habitats over the four seasons had the same specific pattern of species and biological trait abundance in the Beach and the Creek, increasing from the non-covered habitat into the mangrove trees. Although many species shared similar traits, the abundance-driven differences in trait expression between habitats showed the importance of habitat filtering. The results of this study will be useful in the conservation of mangrove forests and they give a deeper understanding of the ecological patterns and functions of benthic macrofaunal communities in the Persian Gulf.