Social behavior involves staying and helping, two individual attributes that vary considerably among organisms. Investigating the ultimate causes of such variation, this study integrates previously separate lines of research by analyzing the joint evolution of altruism and mobility. We unfold the network of selective pressures and derive how these depend on physiological costs, eco-evolutionary feedbacks, and a complex interaction between the evolving traits. Our analysis highlights habitat saturation, both around individuals (local aggregation) and around unoccupied space (local contention), as the key mediator of altruism and mobility evolution. Once altruism and mobility are allowed to evolve jointly, three general insights emerge. First, the cost of mobility affects the origin of altruism, determining whether and how quickly selfishness is overcome. Second, the cost of altruism determines which of two qualitatively different routes to sociality are taken: an evolutionary reduction of mobility, resulting in higher habitat saturation, is either preceded or followed by the adaptive rise of altruism. Third, contrary to conventional expectations, a positive correlation between evolutionarily stable levels of altruism and mobility can arise; this is expected when comparing populations that evolved under different constraints on mobility or that differ in other life-history traits.