Margarine originated with the discovery by French chemist Michel Eugène Chevreul in 1813 of margaric acid.
A new recipe was created in response to a competitive challenge from the French govern by order of Napoleon III. Who was looking for a cheap and stable substitute for butter to feed the military troops and lower class of French population. Napoleon offered a big prize to anyone who could pull it off.
In 1869 Hippolyte Mège-Mouriès, during the Franco-Prussian wars improved margerine. Won the prize from Napoleon III for best improved recipe for margarine.
The original formulation of margarine was made with beef fat. Today most margarine is produced with vegetable oil.