Idioms are quite illogical anyway. There's no point in trying to explain to foreigners that it's OK to say "not worth a bean" but that "not worth a pea" is unidiomatic, though there was a time when it looked like being a close-run thing: some people were saying "not worth a pea", or perhaps "not worth a pease", in Chaucer's time. (Chaucer's innkeeper said "not worth a turd".) Why "pea" faded and "bean" stayed on is just one of those mysteries. "Pea" came back strongly much later, when "the pea" meant the horse best tipped to win. I believe it is still used in a similar sense by Australians, or was till recently, for an up- and-coming politician: this came from the old three- thimble game, in which the punters had to guess which thimble the pea was under.
But bean is much the more versatile word, heaven knows why. In the 19th century, far from being worthless, a "bean" was a name for a gold sovereign. By the 20th, it seems to have been devalued again, when bankrupts were said to be without so much as a bean. At the same time, "old bean" was a term of affection, while a slap-up dinner was still being called a beanfeast, which is another mystery. When first used by the Georgians a beanfeast was specifically a dinner given by employers for the workers, who couldn't have been too happy if it had consisted mainly of the humble, low-value bean.
One gets the feeling that bean is a word that's come in handy when no one could think of a better one at the time. There seems no reason, for example, why beans should be what you give to an opponent whom you aim to flatten. But one can see some logic in the expression "full of beans". Also in saying that an indiscreet person is spilling (that is to say regurgitating) the beans; the OED dates this back to the America of 1911, and reminds us that "spilling his guts" meant the same.
Beans were used in elections in ancient Greece as an alternative to the more usual pebbles, or psephoi. Instead of putting your cross you dropped your pebble, or bean, into the urn of your choice. There's just a chance, but only a chance, that Mr Mandelson had this democratic practice at the back of his mind when he said that those NEC elections didn't make a bean of difference.