Understanding the mechanisms driving phenotypic variation in traits facing intensified selection from climate change is a crucial step in developing effective conservation and restoration initiatives. This is particularly true for reef-building corals, which are among the most vulnerable to climate change and are in dramatic decline globally. At the Rowley Shoals in Western Australia, the prominent reef flat becomes exposed on low tide and the stagnant water in the shallow atoll lagoons heats up, creating a natural laboratory for characterising the mechanisms that control phenotypic responses to different environments. We combined whole genome re-sequencing, common garden heat stress experiments, transcriptome-wide gene expression analyses, and symbiont metabarcoding to explore the mechanisms that facilitate survival in contrasting habitat conditions. Our data show that, despite high gene flow between habitats, spatially varying selection drives subtle shifts in allele frequencies at hundreds of loci. These changes were concentrated into several islands of divergence spanning hundreds of SNPs that showed strong linkage disequilibrium and were associated with a coordinated increase in minor allele frequencies in corals taken from the lagoon habitat, where the range of environmental conditions is greatest. Common garden heat stress assays showed individuals from the lagoon exhibited higher bleaching resistance than colonies from the reef slope, and RNAseq identified pronounced physiological differences between the corals from the two habitats, primarily associated with molecular pathways including cell signalling, ion transport and metabolism. Despite the pronounced physioloigical and environmental differences between habitats, metabarcoding of the Symbiodiniaceae ITS2 region revealed all colonies to be associated exclusively with the genus Cladocopium, with no detectable differences between habitats. This study contributes to the growing number of studies documenting the complex mechanisms that facilitate coral survival in extreme environments, and showcases the utility of combining multiple sequencing techniques to unravel complex climate-related traits.