He measured the amount of heat produced by a wide variety of processes including an electric current, friction of water against glass, compressing gas in a cylinder and turning wheels in water. It became clear to Joule that, if the 'law of conservation' was true, then heat must be considered a form of energy. If 100 units of potential energy were involved in the conversion, and only 80 units of kinetic energy were recovered, the missing 20 units of energy could be found as heat. Joule's work also could be taken a step further. If the conservation law were true, then any phenomenon capable of producing heat would also have to be considered a form of energy.
Sunlight can warm up a concrete sidewalk, so light is a form of energy.
So the 'law of conservation of work' became a much broader law, the 'law of conservation of energy'. Joule probably understood this concept, but it was a German physicist and biologist Hermann von Helmholtz who explicitly stated this law in it clearest form in 1847, so he is generally given the credit for its discovery.