The Phrase Finder describes that this expression means to divulge a secret either inadvertently or maliciously. One theory is that the expression had its origin with a voting system used in ancient Greece using white and black beans, with a single black bean preventing passage. If the collector spilled the beans before the vote was complete and a black bean was seen, the vote wasn’t counted. However, the phrase wasn’t recorded until in the early 20th century. “Spill was used in the 14th century with to mean spilling blood and killing, and it was used to mean divulge in the 16th century. It was used in U.S. in the 20th century to mean “spoil the beans” or “upset the applecart.” It was first used in 1911 to mean upsetting a stable situation by talking out of turn.