Megaherbivores have pervasive ecological effects. In African rainforests, elephants can increase aboveground carbon, though the mechanisms are unclear. Here we combine a large unpublished dataset of forest elephant feeding with published browsing preferences totaling > 120,000 records covering 700 plant species, including nutritional data for 102 species. Elephants increase carbon stocks by: 1) promoting high wood density tree species via preferential browsing on leaves from low wood density species, which are more digestible; 2) dispersing seeds of trees that are relatively large and have the highest average wood density among tree guilds based on dispersal mode. Loss of forest elephants could cause a 5-12% decline in carbon stocks due to regeneration failure of elephant-dispersed trees and an increase in abundance of low wood density trees. These results show the major importance of megaherbivores in maintaining diverse, high-carbon tropical forests. Successful elephant conservation will contribute to climate mitigation at a scale of global relevance.