We present a first-principles approach for the computation of the magnetic Gibbs free energy of materials using magnetically constrained supercell calculations. Our approach is based on an adiabatic approximation of slowly varying local moment orientations, the so-called finite-temperature disordered local moment picture. It describes magnetic phase transitions and how electronic and/or magnetostructural mechanisms generate a discontinuous (first-order) character. We demonstrate that the statistical mechanics of the local moment orientations can be described by an affordable number of supercell calculations containing noncollinear magnetic configurations. The applicability of our approach is illustrated by firstly studying the ferromagnetic state in bcc Fe. We then investigate the temperature-dependent properties of a triangular antiferromagnetic state stabilizing in two antiperovskite systems Mn3AN (A = Ga, Ni). Our calculations provide the negative volume expansion of these materials as well as the ab initio origin of the discontinuous character of the phase transitions, electronic and/or magnetostructural, in good agreement with experiment.