We present U BV { R _ { C } } { I _ { C } } photometry of the optical afterglow of the gamma-ray burst ( catalog GRB~021004 ) taken at the Nordic Optical Telescope between approximately eight hours and 30 days after the burst . This data is combined with an analysis of the 87 ksec Chandra X -ray observations of ( catalog GRB~021004 ) taken at a mean epoch of 33 hours after the burst to investigate the nature of this GRB . We find an intrinsic spectral slope at optical wavelengths of \beta _ { U H } = 0.39 \pm 0.12 and an X -ray slope of \beta _ { X } = 0.94 \pm 0.03 . There is no evidence for color evolution between 8.5 hours and 5.5 days after the burst . The optical decay becomes steeper approximately five days after the burst . This appears to be a gradual break due to the onset of sideways expansion in a collimated outflow . Our data suggest that the extra-galactic extinction along the line of sight to the burst is between A _ { V } \approx 0.3 and A _ { V } \approx 0.5 and has an extinction law similar to that of the Small Magellanic Cloud . The optical and X -ray data are consistent with a relativistic fireball with the shocked electrons being in the slow cooling regime and having an electron index of p = 1.9 \pm 0.1 . The burst occurred in an ambient medium that is homogeneous on scales larger than approximately 10 ^ { 18 } cm but inhomogeneous on smaller scales . The mean particle density is similar to what is seen for other bursts ( 0.1 \lesssim n \lesssim 100 cm ^ { -3 } ) . Our results support the idea that the brightening seen approximately 0.1 days was due to interaction with a clumpy ambient medium within 10 ^ { 17 } – 10 ^ { 18 } cm of the progenitor . The agreement between the predicted optical decay and that observed approximately ten minutes after the burst suggests that the physical mechanism controlling the observed flux at t \approx 10 minutes is the same as the one operating at t > 0.5 days .