The company we now know as BMW actually started as Rapp-Motorenwerke, a company that manufactured low-quality aircraft engines in a converted bicycle factory near Munich back in 1913. That company later merged with another more successful engine company called Gustav Flugmaschinefabrik, to form Bayerische Flugzeug-Werke (Bavarian Aircraft Works) aka BFW. After securing a contract with the German military they again changed names in 1916 to Bayerische Motore Werke or BMW for short. They then produced the war planes that the Germans used in the first World War.
As part of the Versailles Treaty at the conclusion of WWI, Germany was no longer allowed to produce military aircraft (though, they still did). BMW still secretly produced airplane engines but with the decreased demand for military aircraft engines and a weak post-war German economy, business was struggling. They had to branch out and produce engines for trucks, boats, farming equipment, motorcycles, and finally in 1928, automobiles.
During World War II, BMW found itself producing military vehicles and even rockets for Nazi Germany's military. Though their Munich plant was destroyed during the Allied invasion of Germany, the company survived the war, and was allowed to repair vehicles for the Allied troops during the postwar reconstruction. In the decades after the War, BMW gained international renown for its cars. However, if you look at their logo, it's actually a picture of a propeller, in reference to the company's past.
For a complete history of BMW