M&M's were first introduced commercially in 1941 by Forrest Mars, Sr.  Forrest got the idea for the candy after observing soldiers eating chocolate pellets with a hard shell during the Spanish Civil War.  The candy was made with a hard shell so that soldiers could carry the chocolate during warm weather.  The hard shell would make it much harder for the chocolate to melt.

M&M's were quickly adopted by the United States Armed Forces during World War II.  The chocolates were initially designed to allow easy transport and consumption for the soldiers in the war.  During the war, M&M's were exclusively sold to the military.

[Source: Wikipedia]