Agricultural practices constitute both the greatest cause of biodiversity loss and the greatest opportunity for conservation1,2, given the shrinking scope of protected areas in many regions. Recent studies have documented the high levels of biodiversity—across many taxa and biomes—that agricultural landscapes can support over the short term1,3,4. However, little is known about the long-term effects of alternative agricultural practices on ecological communities4,5 Here we document changes in bird communities in intensive-agriculture, diversified-agriculture and natural-forest habitats in 4 regions of Costa Rica over a period of 18 years. Long-term directional shifts in bird communities were evident in intensive- and diversified-agricultural habitats, but were strongest in intensive-agricultural habitats, where the number of endemic and International Union for Conservation of Nature (IUCN) Red List species fell over time. All major guilds, including those involved in pest control, pollination and seed dispersal, were affected. Bird communities in intensive-agricultural habitats proved more susceptible to changes in climate, with hotter and drier periods associated with greater changes in community composition in these settings. These findings demonstrate that diversified agriculture can help to alleviate the long-term loss of biodiversity outside natural protected areas1.