Iceberg calving has been implicated in the retreat and acceleration of glaciers and ice shelves along the margins of the Greenland and Antarctic ice sheets1,2,3,4. Accurate projections of sea-level rise therefore require an understanding of how and why calving occurs. Unfortunately, calving is a complex process and previous models of the phenomenon have not reproduced the diverse patterns of iceberg calving observed in nature5,6. Here we present a numerical model that simulates the disparate calving regimes observed, including the detachment of large tabular bergs from floating ice tongues, the disintegration of ice shelves and the capsizing of smaller bergs from grounded glaciers that terminate in deep water. Our model treats glacier ice as a granular material made of interacting boulders of ice that are bonded together. Simulations suggest that different calving regimes are controlled by glacier geometry, which controls the stress state within the glacier. We also find that calving is a two-stage process that requires both ice fracture and transport of detached icebergs away from the calving front. We suggest that, as a result, rapid iceberg discharge is possible in regions where highly crevassed glaciers are grounded deep beneath sea level, indicating portions of Greenland and Antarctica that may be vulnerable to rapid ice loss through catastrophic disintegration.