Abstract Background Endolithic microbes in coral skeletons are known to be a nutrient source for the coral host. In addition to aerobic endolithic algae and Cyanobacteria, which are usually described in the various corals and form a green layer beneath coral tissues, the anaerobic photoautotrophic green sulfur bacteria (GSB) Prosthecochloris is dominant in the skeleton of Isopora palifera. However, due to inherent challenges in studying anaerobic microbes in coral skeleton, the reason for its niche preference and function are largely unknown. Results This study characterized a diverse and dynamic community of endolithic microbes shaped by the availability of light and oxygen. In addition, anaerobic bacteria isolated from the coral skeleton were cultured for the first time to experimentally clarify the role of these GSB. This characterization includes GSB’s abundance, genetic and genomic profiles, organelle structure, and specific metabolic functions and activity. Our results explain the advantages endolithic GSB receive from living in coral skeletons, the potential metabolic role of a clade of coral-associated Prosthecochloris (CAP) in the skeleton, and the nitrogen fixation ability of CAP. Conclusion We suggest that the endolithic microbial community in coral skeletons is diverse and dynamic and that light and oxygen are two crucial factors for shaping it. This study is the first to demonstrate the ability of nitrogen uptake by specific coral-associated endolithic bacteria and shed light on the role of endolithic bacteria in coral skeletons.