The story
The adage originates from the common craft of blacksmithing. It appears in Chaucer's The Tale of Melibee, "right so as whil that iren is hoot men sholden smyte". (Harvard) It gained additional meaning when used as a motto by Joseph Paisley - a blacksmith at Gretna Green who married eloping couples at his anvil. (History in the Margins)
Etymology from Wiktionary, CC BY-SA 4.0.