Upon immunogenic challenge, lymph nodes become mechanically stiff as immune cells activate and proliferate within their encapsulated environments, and with resolution, they reestablish a soft baseline state. Here we show that sensing these mechanical changes in the microenvironment requires the mechanosensor YAP. YAP is induced upon activation and suppresses metabolic reprogramming of effector T cells. Unlike in other cell types in which YAP promotes proliferation, YAP in T cells suppresses proliferation in a stiffness-dependent manner by directly restricting the translocation of NFAT1 into the nucleus. YAP slows T cell responses in systemic viral infections and retards effector T cells in autoimmune diabetes. Our work reveals a paradigm whereby tissue mechanics fine-tune adaptive immune responses in health and disease.