What does the expression “to spill the beans” mean and Where does it come from?

The expression “to spill the beans” means to upset the plans; to relate something fully or prematurely; to let the cat out of the bag; to upset the apple cart.

This American saying came into general use early in the present century, and, of course, the incident that gave rise to it, whatever it may have been, was not recorded.

Very likely it was an actual occurrence, possibly an important occasion at which, say, baked beans were to have been the main dish. Just before serving, or perhaps at the table, the bean pot may have broken, not only causing a mess generally, but also upsetting the plans.

The extended sense, telling something that should not be told, or telling something in detail, seems to have been added from the older, “to know beans,” to know what is what.