For decades theorists struggled to prove this using Maxwell's theory of electromagnetic radiation, but in vain.
In the year 1900 Max Planck was a young theorist at Berlin. The experiments with radiation were continuing, the far infrared part of the spectrum being the most difficult to measure, being heat waves. Based on a hint a he got from the experimentalists at Berlin, Planck made the leap of faith which gave us the mathematical expression of Planck spectrum.
Many years later Planck recalled that he was desperate to get the answer, and he did so by bending the rules of Thermodynamics in a way no one understood. The mysterious counting based on the hypothesis of discretization or ``quantization'' of energy, reproduced the observed spectrum perfectly.