Here are the popular theories (if you can call such grim propositions "popular"):
(1) In the 1500s, "bucket" was a word for a beam or a yoke on which something could be suspended (from the Old French buquet). A pig was often hung by its heels from a beam (or "bucket") before or just after slaughter, and thrashed a bit in its final spasms. Therefore, to "kick the bucket" was to die.
(2) The "bucket" that's a pail has an uncertain etymology, but the OED compares it with the Old English buc, meaning a "pail," a "vessel," or a "belly." A suicide (or someone about to be executed) might stand on an overturned bucket with a noose about his neck, then strangle when the bucket was kicked away. Hence "kicking the bucket" meant dying.
The first published citation for the expression comes from Francis Grose's A Classical Dictionary of the Vulgar Tongue (1785): "To kick the bucket, to die." The expression also appears in a collection of American proverbs from 1789, according to the Random House Historical Dictionary of American Slang.
Random House agrees with the OED that the origin remains uncertain "despite much speculation." But Eric Partridge's A Dictionary of Slang and Unconventional English goes for the slaughterhouse explanation. So does Cassell's Dictionary of Slang, which calls the suicide theory "rather less likely." Wow, thanks for the detailed response, Pat! What's interesting is that a change in the most widely accepted definition of the word "bucket" might have possibly forced us to imagine a new origin for the phrase, in order to keep its meaning intact. I wonder if other phrases have had similar transformations? How else might "kicking the bucket" result in death? Here's two I came up, can you think of any others?