Results are presented from a search for the rare decays B0s→μ+μ− and B0→μ+μ− in pp collisions at s√=7 and 8 TeV, with data samples corresponding to integrated luminosities of 5 and 20 fb−1, respectively, collected by the CMS experiment at the LHC. An unbinned maximum-likelihood fit to the dimuon invariant mass distribution gives a branching fraction B(B0s→μ+μ−)=(3.0+1.0−0.9)×10−9, where the uncertainty includes both statistical and systematic contributions. An excess of B0s→μ+μ− events with respect to background is observed with a significance of 4.3 standard deviations. For the decay B0→μ+μ− an upper limit of B(B0→μ+μ−)<1.1×10−9 at the 95% confidence level is determined. Both results are in agreement with the expectations from the standard model.