Understanding the factors that regulate the induction, quality, and longevity of antiviral T cell responses is essential for devising rational strategies to prevent or combat infections. In this study, we show that interleukin-21 (IL-21), likely produced by CD4(+) T cells, directly influences the generation of polyfunctional CD8(+) T cells and that the number of CD4(+) T cells that produce IL-21 differs markedly between acute and chronic infections. IL-21 regulates the development of CD8(+) T cell exhaustion and the ability to contain chronic lymphocytic choriomeningitis virus infection. Thus, IL-21 serves as a critical helper factor that shapes the functional quality of antiviral CD8(+) T cells and is required for viral control.