Coral reef species, like most tropical species, are sensitive to increasing environmental temperatures, with many species already living close to their thermal maxima. Ocean warming and the increasing frequency and intensity of marine heatwaves are challenging the persistence of reef-associated species through both direct physiological effects of elevated water temperatures and the degradation and loss of habitat structure following disturbance. Understanding the relative importance of habitat degradation and ocean warming in shaping species distributions is critical in predicting the likely biological effects of global warming. Using an automated shuttle box system, we investigated how habitat complexity influences the selection of thermal environments for a common coral reef damselfish, Chromis atripectoralis. In the absence of any habitat (i.e. control), C. atripectoralis avoided temperatures below 22.9 ± 0.8°C and above 31.9 ± 0.6°C, with a preferred temperature (Tpref) of 28.1 ± 0.9°C. When complex habitat was available, individual C. atripectoralis occupied temperatures down to 4.3°C lower (mean ± SE; threshold: 18.6 ± 0.7°C; Tpref: 18.9 ± 1.0°C) than control fish. Conversely, C. atripectoralis in complex habitats occupied similar upper temperatures as control fish (threshold: 31.7 ± 0.4°C; preference: 28.3 ± 0.7°C). Our results show that the availability of complex habitat can influence the selection of thermal environment by a coral reef fish, but only at temperatures below their thermal preference. The limited scope of C. atripectoralis to occupy warmer environments, even when associated with complex habitat, suggests that habitat restoration efforts in areas that continue to warm may not be effective in retaining populations of C. atripectoralis and similar species. This species may have to move to cooler (e.g. deeper or higher latitude) habitats under predicted future warming. The integration of habitat quality and thermal environment into conservation efforts will be essential to conserve of coral reef fish populations under future ocean warming scenarios.