The standard model of particle physics describes the fundamental particles and their interactions via the strong, electromagnetic and weak forces. It provides precise predictions for measurable quantities that can be tested experimentally. The probabilities, or branching fractions, of the strange B meson (B-s(0)) and the B-0 meson decaying into two oppositely charged muons (mu(+) and mu(-)) are especially interesting because of their sensitivity to theories that extend the standard model. The standard model predicts that the B-s(0)->mu(+)mu(-) and B-0 ->mu(+)mu(-) decays are very rare, with about four of the former occurring for every billion B-s(0) mesons produced, and one of the latter occurring for every ten billion B-0 mesons(1). A difference in the observed branching fractions with respect to the predictions of the standard model would provide a direction in which the standard model should be extended. Before the Large Hadron Collider (LHC) at CERN2 started operating, no evidence for either decay mode had been found. Upper limits on the branching fractions were an order of magnitude above the standard model predictions. The CMS (Compact Muon Solenoid) and LHCb(Large Hadron Collider beauty) collaborations have performed a joint analysis of the data from proton-proton collisions that they collected in 2011 at a centre-of-mass energy of seven teraelectronvolts and in 2012 at eight teraelectronvolts. Here we report the first observation of the B-s(0)->mu(+)mu(-) decay, with a statistical significance exceeding six standard deviations, and the best measurement so far of its branching fraction. Furthermore, we obtained evidence for the B-0 ->mu(+)mu(-) decay with a statistical significance of three standard deviations. Both measurements are statistically compatible with standard model predictions and allow stringent constraints to be placed on theories beyond the standard model. The LHC experiments will resume taking data in 2015, recording proton-proton collisions at a centre-of-mass energy of 13 teraelectronvolts, which will approximately double the production rates of B-s(0) and B-0 mesons and lead to further improvements in the precision of these crucial tests of the standard model.