The story
Attested 1665, by which point already in common use; perhaps of naval slang origin. While it is frequently stated that the phrase is derived from cat-o’-nine-tails (“type of whip”), this latter term is only attested from 1695, and hence this idiom presumably derived from literally swinging a cat around, as by the tail.
Etymology from Wiktionary, CC BY-SA 4.0.