The story
According to The Oxford English Dictionary and The Oxford Dictionary of Idioms, the phrase possibly refers to the act of placing an individual who has been rescued from drowning over a barrel to allow their lungs to clear of water.
Etymology from Wiktionary, CC BY-SA 4.0.