We present the results of a search for the standard model Higgs boson production in the rare decay channel in proton-proton collisions at \mbox{ and 8~TeV}. The data samples, recorded by the CMS experiment at the LHC, correspond to integrated luminosities of ~fb at 7 TeV and of ~fb at 8 TeV. To enhance the Higgs signal over the dominant Drell-Yan background, the events are categorized by topologies corresponding to different production processes. Upper limits on the production cross section at the 95\% confidence level are reported for Higgs boson masses in the range from 120 to 150~\GeVcc. At the Higgs boson mass of 125~\GeVcc the observed (expected) 95\% C.L. upper limit on the production rate is found to be 7.4 () times the standard model prediction. %For a dimuon mass at 149~\GeVcc, a broad excess corresponding to a local significance of 2.8~\sigma %and 1.6~\sigma after taking into account the look-elsewhere effect is observed. Results of the first search for the Higgs boson production in the rare decay is also reported.