STAT3 is a master regulator of the immune responses. Here we show that M. tuberculosis-infected stat3fl/fl lysm cre mice, defective for STAT3 in myeloid cells, contained lower bacterial load in lungs and spleens, reduced granuloma extension but higher levels of pulmonary neutrophils. STAT3-deficient macrophages showed no improved control of intracellular mycobacterial growth. Instead, protection associated to elevated ability of stat3fl/fl lysm cre antigen-presenting cells (APCs) to release IL-6 and IL-23 and to stimulate IL-17 secretion by mycobacteria-specific T cells. The increased IL-17 secretion accounted for the improved control of infection since neutralization of IL-17 receptor A in stat3fl/fl lysm cre mice hampered bacterial control. APCs lacking SOCS3, which inhibits STAT3 activation via several cytokine receptors, were poor inducers of priming and of the IL-17 production by mycobacteria-specific T cells. In agreement, socs3fl/fl cd11c cre mice deficient of SOCS3 in DCs showed increased susceptibility to M. tuberculosis infection. While STAT3 in APCs hampered IL-17 responses, STAT3 in mycobacteria-specific T cells was critical for IL-17 secretion, while SOCS3 in T cells impeded IL-17 secretion. Altogether, STAT3 signalling in myeloid cells is deleterious in the control of infection with M. tuberculosis.