The problem of the optimal control of the reorientation of a spacecraft (SC) from an arbitrary initial angular position to the given final angular position is solved analytically in the presence of ellipsoidal constraints on the phase variables and control functions (the angular velocity and force moment are limited). The turning time is minimized. The case when the maximal allowable kinetic energy of rotation is a significant limitation is considered. The construction of the optimal control of a turn is based on quaternion variables and models. It is shown that during the optimal turn, the moment of forces is parallel to a straight line that is stationary in inertial space, and when the SC rotates, the direction of the kinetic momentum is constant relative to the inertial coordinate system. Analytical equations and relations for finding the optimal control program are written out. The calculation formulas are given for determining the time characteristics of the maneuver and calculating the duration of acceleration and deceleration. For an axisymmetric SC, the posed problem of the optimal control is solved completely: the dependences are obtained as explicit functions of time for the control variables and relations for calculating the key parameters of the control law. A numerical example and the results of mathematical modeling of the motion of an SC under the optimal control are given, demonstrating the practical feasibility of the developed method for controlling the orientation of an SC.