  We develop a general theory describing the thermodynamical behavior of open
quantum systems coupled to thermal baths beyond perturbation theory. Our
approach is based on the exact time-local quantum master equation for the
reduced open system states, and on a principle of minimal dissipation. This
principle leads to a unique prescription for the decomposition of the master
equation into a Hamiltonian part representing coherent time evolution and a
dissipator part describing dissipation and decoherence. Employing this
decomposition we demonstrate how to define work, heat, and entropy production,
formulate the first and second law of thermodynamics, and establish the
connection between violations of the second law and quantum non-Markovianity.
