We present a first-principles study (local density approximation) of the structural properties of forsterite under pressure. This highly anisotropic magnesium orthosilicate is the most abundant phase of the Earth's upper mantle, and its elastic properties determine the rheology of this region. We perform full structural optimizations and investigate its compressive behavior up to 25 GPa. We obtain a pressure dependence of lattice parameters that agrees well with experiments to 17.2 GPa. We predict that the coordination polyhedra compress essentially isotropically, and we explain the anisotropy of forsterite in terms of the nonuniform distribution of coordination polyhedra having different but nearly uniform compressibilities. In agreement with Brodholt et al. (1996), we do not find theoretical evidence for sudden changes in compression mechanisms in this mineral as had been suggested from experiments. Our results support the hypothesis that such compressive anomalies are caused by solidification of the pressure medium.