In short:
William Thomson (or Thomsen) later Lord Kelvin, an Irish-born scientist, was the first to study the cooling of gases on expansion into a vacuum, by the mid 19th century, realizing that heat is related with molecular motion.
Benjamin Thompson, an American-born scientist working as director of the Bavarian arsenal by the end of the 18th century, noted the large amount of heat produced in the process of boring cannons. He, then, concluded that heat is not a conserved fluid. He suggested that heating was associated with mechanical work by the boring tool.
By about half a century later the British physicist James P. Joule confirmed Thompson's observations, and quantified the relation between heat and energy (mechanical, electrical and chemical), bringing thermal phenomena under the powerful conservation-of-energy law. The SI energy unit is named after Joule in recognition of this major synthesis in physics.