The ecological effects of ocean acidification (OA) from rising atmospheric carbon dioxide (CO2) on benthic marine communities are largely unknown. We investigated in situ the consequences of long-term exposure to high CO2 on coral-reef-associated macroinvertebrate communities around three shallow volcanic CO2 seeps in Papua New Guinea. The densities of many groups and the number of taxa (classes and phyla) of macroinvertebrates were significantly reduced at elevated CO2 (425–1100 µatm) compared with control sites. However, sensitivities of some groups, including decapod crustaceans, ascidians and several echinoderms, contrasted with predictions of their physiological CO2 tolerances derived from laboratory experiments. High CO2 reduced the availability of structurally complex corals that are essential refugia for many reef-associated macroinvertebrates. This loss of habitat complexity was also associated with losses in many macroinvertebrate groups, especially predation-prone mobile taxa, including crustaceans and crinoids. The transition from living to dead coral as substratum and habitat further altered macroinvertebrate communities, with far more taxa losing than gaining in numbers. Our study shows that indirect ecological effects of OA (reduced habitat complexity) will complement its direct physiological effects and together with the loss of coral cover through climate change will severely affect macroinvertebrate communities in coral reefs.