Climate change is increasingly putting milk production from cattle-based dairy systems in north sub-Saharan Africa (NSSA) under stress, threatening livelihoods and food security. Here we combine livestock heat stress frequency, dry matter feed production and water accessibility data to understand where environmental changes in NSSA’s drylands are jeopardizing cattle milk production. We show that environmental conditions worsened for ∼17% of the study area. Increasing goat and camel populations by ∼14% (∼7.7 million) and ∼10% (∼1.2 million), respectively, while reducing the dairy cattle population by ∼24% (∼5.9 million), could result in ∼0.14 Mt (+5.7%) higher milk production, lower water (−1,683.6 million m3, −15.3%) and feed resource (−404.3 Mt, −11.2%) demand—and lower dairy emissions by ∼1,224.6 MtCO2e (−7.9%). Shifting herd composition from cattle towards the inclusion of, or replacement with, goats and camels can secure milk production and support NSSA’s dairy production resilience against climate change.