We present a general construction of KMS states in the framework of perturbative algebraic quantum field theory (pAQFT). Our approach may be understood as an extension of the Schwinger-Keldysh formalism. We obtain in particular the Wightman functions at positive temperature, thus solving a problem posed some time ago by Steinmann (Commun Math Phys 170:405-416, 1995). The notorious infrared divergences observed in a diagrammatic expansion are shown to be absent due to a consequent exploitation of the locality properties of pAQFT. To this avail, we introduce a novel, Hamiltonian description of the interacting dynamics and find, in particular, a precise relation between relativistic QFT and rigorous quantum statistical mechanics.