Magnetic cooling is a highly efficient refrigeration technique with the potential to replace the traditional vapor compression cycle. It is based on the magnetocaloric effect, which is associated with the temperature change of a material when placed in a magnetic field. We present experimental evidence for the origin of the giant entropy change found in the most promising materials, in the form of an electronic reconstruction caused by the competition between magnetism and bonding. The effect manifests itself as a redistribution of the electron density, which was measured by X-ray absorption and diffraction on MnFe(P,Si,B). The electronic redistribution is consistent with the formation of a covalent bond, resulting in a large drop in the Fe magnetic moments. The simultaneous change in bond length and strength, magnetism, and electron density provides the basis of the giant magnetocaloric effect. This new understanding of the mechanism of first order magneto-elastic phase transitions provides an essential step for new and improved magnetic refrigerants.