In ecology and conservation, habitat diversity is often predicted to promote the diversity of animal communities because a greater variety of habitats increases the opportunities for niche partitioning and the coexistence of species specialized on different resources. Although positive correlations between habitat diversity and the diversity of associated animals are often observed, the underlying mechanisms are only starting to emerge and have never been specifically tested in the marine environment. Scleractinian corals constitute the primary habitat-forming organisms on coral reefs and as such play an important role in structuring associated reef fish communities. Using the same field experiment in two locations differing in regional fish species composition, we directly tested the effects of coral species richness and composition on the diversity, abundance and structure of the local fish community. Coral species richness overall had a positive effect on fish species richness, but no effect was found on total fish abundance or evenness. At both locations, certain coral species alone supported similar levels of fish diversity and abundance compared to treatments of higher coral species richness, suggesting that particular coral species are important in promoting high local fish diversity. Furthermore, different microhabitats (coral species) at both locations supported very different fish communities, indicating that most reef fish species distinguish coral habitat at the level of coral species. Fish communities colonizing treatments of higher coral species richness represented a combination of those inhabiting the constituent coral species. These findings suggest that mechanisms underlying habitat-animal interaction in the terrestrial environment also apply to marine systems and highlight the importance of coral diversity to local fish diversity. The loss of key coral species is likely to have a disproportionate impact on the biodiversity of associated fish communities.