The alignment system for the muon spectrometer of the CMS detector comprises three independent subsystems of optical and analog position sensors. It aligns muon chambers with respect to each other and to the central silicon tracker. System commissioning at full magnetic field began in 2008 during an extended cosmic ray run. The system succeeded in tracking muon detector movements of up to 18 mm and rotations of several milliradians under magnetic forces. Depending on coordinate and subsystem, the system achieved chamber alignment precisions of 140-350 mu m and 30-200 mu rad, close to the precision requirements of the experiment. Systematic errors on absolute positions are estimated to be 340-590 mu m based on comparisons with independent photogrammetry measurements.