The problem of the dynamic optimal turn of a spacecraft (SC) from an arbitrary initial to the required final angular position is considered and solved. The time required for the turn is fixed. To optimize the rotation control program, a combined quality criterion is used, the minimized functional characterizes the energy costs and combines the costs of control forces and the rotation energy integral in the given proportion. The problem is solved analytically. The construction of the optimal turn control is based on quaternion models and the maximum principle of L.S. Pontryagin. The optimality conditions are written in analytical form, and the properties of the optimal motion are studied. Formalized equations and calculation expressions are given to determine the optimal turning program. The control law is formulated as an explicit dependence of the control variables on the phase coordinates. Analytical equations and relations are written out for finding the optimal motion of the SC. The key relationships are given that determine the optimal values of the parameters of the rotation control algorithm. A constructive scheme for solving the boundary value problem of the maximum principle for arbitrary turning conditions is also described. For an axisymmetric SC, a complete solution of the reorientation problem in a closed form is given. An example and results of the mathematical modeling of the SC's motion dynamics under the optimal control are given, demonstrating the practical feasibility of the developed method for controlling the spatial orientation of an SC.