Antibiotic-resistant infections annually claim hundreds of thousands of lives worldwide. This problem is exacerbated by exchange of resistance genes between pathogens and benign microbes from diverse habitats. Mapping resistance gene dissemination between humans and their environment is a public health priority. Here we characterized the bacterial community structure and resistance exchange networks of hundreds of interconnected human faecal and environmental samples from two low-income Latin American communities. We found that resistomes across habitats are generally structured by bacterial phylogeny along ecological gradients, but identified key resistance genes that cross habitat boundaries and determined their association with mobile genetic elements. We also assessed the effectiveness of widely used excreta management strategies in reducing faecal bacteria and resistance genes in these settings representative of low- and middle-income countries. Our results lay the foundation for quantitative risk assessment and surveillance of resistance gene dissemination across interconnected habitats in settings representing over two-thirds of the world's population.