We've learned about energy conservation in a mechanical system, where the energy in microscopic degrees of freedom was considered to be "lost".
For a thermodynamic system, these microscopic degrees of freedom are included in the energy conservation statement.
Energy Conservation (1st Law of Thermodynamics):   dE = dQ + dW
dE ≡ change in the total energy of the system
E = Emechanical + Ethermal
dQ ≡ heat added to the system
dW ≡ work done on the system
Heat is a form of energy that can be transferred between a system and its surroundings because of a temperature difference between them. Microscopically, heat is associated with molecular motion.