Understanding the nature of the γ-ray burst phenomenon is one of the outstanding problems of modern astrophysics. The identification of counterparts at optical wavelengths is considered a crucial factor for determining the origin of these events. Here we report the detection and temporal properties of a variable optical source, which has been identified, as the counterpart of the X-ray transient associated with the γ-ray burst GRB970508 (ref. 3). The initial optical images were obtained only 5.8 hours after the initial γ-ray burst, after which the optical source was observed to brighten over the next two days before declining in luminosity with a t-1 power law. The decline in brightness follows a form predicted by many relativistic fireball models for γ-ray bursts, although the initial rise does not appear to be compatible with the simplest of these models. The observed fluence of the source at visible wavelengths over the period spanned by our observations is >=4.6 × 10-8 erg cm-2, about 3% of the fluence of the γ-ray burst itself.