Context. Stellar mergers are expected to take place in numerous circumstences in the evolution of stellar systems. In particular, they are considered as a plausible origin of stellar eruptions of the V838 Mon type. V1309 Sco is the most recent eruption of this type in our Galaxy. The object was discovered in September 2008. Aims. Our aim is to investigate the nature of V1309 Sco. Methods. V1309 Sco has been photometrically observed in course of the OGLE project since August 2001. We analyse these observations in different ways. In particular, periodogram analyses were done to investigate the nature of the observed short-term variability of the progenitor. Results. We find that the progenitor of V1309 Sco was a contact binary with an orbital period of ∼1.4 day. This period was decreasing with time. The light curve of the binary was also evolving, indicating that the system evolved towards its merger. The violent phase of the merger, marked by the systematic brightenning of the object, began in March 2008, i.e. half a year before the outburst discovery. We also investigate the observations of V1309 Sco during the outburst and the decline and show that they can be fully accounted for within the merger hypothesis. Conclusions. For the first time in the literature we show from direct observations that contact binaries indeed end up by merging into a single object, as was suggested in numerous theoretical studies of these systems. Our study also shows that stellar mergers indeed result in eruptions of the V838 Mon type.