Halophytes play important roles in coastal ecosystems. However, few reports have described bacterial communities related to halophytes, and the distribution patterns of these bacteria in different plant tissues have been rarely compared. This paper mainly studied the diversity and community structure of endophytic and rhizosphere (Rh) bacteria related to the halophyte Messerschmidia sibirica, a dominant species in the coastal zone of Shandong Peninsula, China. We collected leaf (Lf), stem (Sm), root (Rt), Rh, and bulk (Bl) control soil samples, and sequenced the V5–V7 region of the bacterial 16S rRNA gene using the Illumina HiSeq platform to identify bacterial communities originating from different plant habitats. We found that the bacterial richness and diversity in Rh were significantly higher than those in the leaves, Sm, and Rt, but lower than those of the Bl control soil. In total, 37 phyla and 438 genera were identified. Microbial-diversity analysis showed that Proteobacteria and Actinobacteria were the dominant phyla and that Pseudomonas, Bacillus, Sphingomonas, Streptomyces, Microbacterium, Rhizobium, and Nocardioides were the dominant genera. However, there were clear differences in community diversity and structure among the samples. Endophytic bacteria community in Lf, Sm, and Rt shared more similarity than those in Rh and Bl control soil. The numbers of operational taxonomic units exclusive to the Lf, stem, Rt, Rh, and Bl control soil samples were 51, 43, 122, 139, and 922, respectively, implying habitat-specific patterns. Principal coordinate analysis demonstrated differences were apparent in the bacterial communities associated with habitats. On the whole, M. sibirica affected bacterial diversity and structured the bacterial community. This study provides insight into the complex microbial compositions of coastal halophytes.