Cyanobacteria act as primary producers of carbon and nitrogen in nutrient-poor ecosystems such as mangroves. This important group of microorganisms plays a critical role in sustaining the productivity of mangrove ecosystems, but the structure and function of cyanobacteria assemblages can be perturbed by anthropogenic influences. The aim of this work was to assess the community structure and ecological drivers that influence the cyanobacterial community harboured in two Brazilian mangrove soils, and examine the long-term effects of oil contamination on these keystone species. Community fingerprinting results showed that, although cyanobacterial communities are distinct between the two mangroves, the structure and diversity of the assemblages exhibit similar responses to environmental gradients. In each ecosystem, cyanobacteria occupying near-shore areas were similar in composition, indicating importance of marine influences for structuring the community. Analysis of 16S rRNA sequences revealed the presence of diverse cyanobacterial communities in mangrove sediments, with clear differences among mangrove habitats along a transect from shore to forest. While near-shore sites in both mangroves were mainly occupied by Prochlorococcus and Synechococcus genera, sequences retrieved from other mangrove niches were mainly affiliated with uncultured cyanobacterial 16S rRNA. The most intriguing finding was the large number of potentially novel cyanobacteria 16S rRNA sequences obtained from a previously oil-contaminated site. The abundance of cyanobacterial 16S rRNA sequences observed in sites with a history of oil contamination was significantly lower than in the unimpacted areas. This study emphasized the role of environmental drivers in determining the structure of cyanobacterial communities in mangrove soils, and suggests that anthropogenic impacts may also act as ecological filters that select cyanobacterial taxa. These results are an important contribution to our understanding of the composition and relative abundance of previously poorly described cyanobacterial assemblages in mangrove ecosystems.