Mangrove forests are one of the world's most threatened tropical ecosystems with global loss exceeding 35% (ref. 1). Juvenile coral reef fish often inhabit mangroves, but the importance of these nurseries to reef fish population dynamics has not been quantified. Indeed, mangroves might be expected to have negligible influence on reef fish communities: juvenile fish can inhabit alternative habitats and fish populations may be regulated by other limiting factors such as larval supply or fishing. Here we show that mangroves are unexpectedly important, serving as an intermediate nursery habitat that may increase the survivorship of young fish. Mangroves in the Caribbean strongly influence the community structure of fish on neighbouring coral reefs. In addition, the biomass of several commercially important species is more than doubled when adult habitat is connected to mangroves. The largest herbivorous fish in the Atlantic, Scarus guacamaia, has a functional dependency on mangroves and has suffered local extinction after mangrove removal. Current rates of mangrove deforestation are likely to have severe deleterious consequences for the ecosystem function, fisheries productivity and resilience of reefs. Conservation efforts should protect connected corridors of mangroves, seagrass beds and coral reefs.