The phrase comes down from the days of witchcraft. At the witches' covens, the master of ceremonies represented the Devil, disguised as a man or a goat. He challenged one of his more promising neophytes to dance and in competition that followed, the devil of course would win, his competition usually dying of heart failure or exhaustion. (Radford, Encyclopaedia of Phrases and Origins)