Coral reefs face a diverse array of threats, from eutrophication and overfishing to climate change. As live corals are lost and their skeletons eroded, the structural complexity of reefs declines. This may have important consequences for the survival and growth of reef fish because complex habitats mediate predator-prey interactions [1, 2] and influence competition [3-5] through the provision of prey refugia. A positive correlation exists between structural complexity and reef fish abundance and diversity in both temperate and tropical ecosystems [6-10]. However, it is not clear how the diversity of available refugia interacts with individual predator-prey relationships to explain emergent properties at the community scale. Furthermore, we do not yet have the ability to predict how habitat loss might affect the productivity of whole reef communities and the fisheries they support. Using data from an unfished reserve in The Bahamas, we find that structural complexity is associated not only with increased fish biomass and abundance, but also with nonlinearities in the size spectra of fish, implying disproportionately high abundances of certain size classes. By developing a size spectrum food web model that links the vulnerability of prey to predation with the structural complexity of a reef, we show that these nonlinearities can be explained by size-structured prey refugia that reduce mortality rates and alter growth rates in different parts of the size spectrum. Fitting the model with data from a structurally complex habitat, we predict that a loss of complexity could cause more than a 3-fold reduction in fishery productivity.