We tested the habitat filtering hypothesis by measuring the phylogenetic structure in marine bacterial communities before and after experimentally induced stress. The habitat filtering hypothesis predicts that phylogenetic clustering (mean relatedness) should increase as the environment becomes suitable for only a subset of the original community. We show that community composition and phylogenetic structure were considerably changed with changes in salinity and dissolved organic carbon. Community composition showed no consistent patterns, while the phylogenetic relatedness between species consistently increased with treatment. We have no information about species interactions in our system, but the phylogenetic signal is strong enough to suggest that habitat filtering is the dominant assembly process. Our results support the hypothesis that habitat characteristics and environmental stress can 'filter' a community so that only closely related species can persist. This non-random phylogenetic signal also implies a relationship between ecologically relevant characteristics and species relatedness.