Behavioral innovations can be ecologically transformative for lineages that perform them and for their associated communities. Many ecologically dominant, superorganismal, and speciose ant lineages use a mouth-to-mouth fluid exchange behavior - trophallaxis - to share both exogenously sourced and endogenously produced materials across their colonies, while lineages that are less abundant, less cooperative and less speciose tend not to perform this behavior. How and why this behavior evolved and fixed in only some ant lineages remains unclear and whether this trait enables ants' ecological dominance is not yet understood. Here we show that trophallaxis evolved in two major events ~110 Ma in lineages that today encompass 36% of ants, and in numerous smaller and more recent events. We found that trophallaxis evolved early only in ant lineages that had reduced intra-colonial conflict by losing workers ability to reproduce. Our causal models indicate that this signature behavior of superorganismal ants required social cooperation and ecological opportunism, and likely contributed to the large colony sizes and speciation patterns of the ants that use it and dominate our landscapes today. We hypothesize that the early evolution of trophallaxis was brought about by a major shift in terrestrial ecosystems through the origin and diversification of flowering plants and the consequent opportunistic inclusion of nectar and sap-sucker honeydew in the ant diet.