A search for the B0→K+K- decay is performed using pp-collision data collected by LHCb. The data set corresponds to integrated luminosities of 1.0 and 2.0 fb-1 at center-of-mass energies of 7 and 8 TeV, respectively. This decay is observed for the first time, with a significance of more than 5 standard deviations. The analysis also results in an improved measurement of the branching fraction for the Bs0→π+π- decay. The measured branching fractions are B(B0→K+K-)=(7.80±1.27±0.81±0.21)×10-8 and B(Bs0→π+π-)=(6.91±0.54±0.63±0.19±0.40)×10-7. The first uncertainty is statistical, the second is systematic, the third is due to the uncertainty on the B0→K+π- branching fraction used as a normalization. For the Bs0 mode, the fourth accounts for the uncertainty on the ratio of the probabilities for b quarks to hadronize into Bs0 and B0 mesons.