Margarine is named after a pearl, though nothing about it looks like one.
The trail starts with the French chemist Michel Eugène Chevreul. Etymonline says he coined margarin in 1813, from acide margarique, "margaric acid," for a fatty substance from animal fats. Grammarphobia dates the naming of the acid itself to 1816, so sources differ by a few years. The name comes from the Greek margaritēs, "pearl," because the crystals had a pearly shine. The same Greek word gave us the name Margaret. Etymonline's Margaret entry says the Greek word's ultimate origin is unknown, probably a loanword from an Eastern language.
Chevreul took his margaric acid for a distinct fatty acid, and so did other chemists. Wikipedia says that in 1853 Wilhelm Heinrich Heintz showed it was really a mixture of stearic and palmitic acids. The Oxford English Dictionary, as quoted by Grammarphobia, adds that neither Chevreul's "margarine" nor the later "oleomargarine" was a definite chemical compound. Chemists eventually dropped both terms.
The butter substitute arrived in 1869. The French scientist Hippolyte Mège-Mouriès patented an artificial butter, reportedly in response to a prize Napoleon III offered for a cheaper butter substitute. He used partly edible fats and oils, and the product took the chemists' word for its name. The word "oléomargarine" had been coined earlier, in 1854, from oléine and margarine, and "oleomargarine" for the beef-fat spread is recorded in English in 1873. The shorter "margarine" appears in English the same year.
So the name describes a chemistry mistake, not the food. What was called pearly was a mixture of fats that Chevreul thought was one thing, and the spread inherited the label.
There is a small pronunciation postscript. The word was originally said with a hard g, as the spelling suggests. The soft g came in during the early twentieth century, possibly influenced by words like "margin" and the name Margaret. Lexicographers accepted the soft g in 1913 as a lesser variant, and by 1917 the phonetician Daniel Jones listed it as preferred.
Britons later clipped the word to "marge," which turns up in James Joyce's Ulysses in 1922.