Within the framework of analytic control theory, we offer a solution to the problem of optimal (in a certain sense) stabilization of rotational motion of a rigid body with an ellipsoidal cavity that is entirely filled by an ideal fluid, and with three controlled pendulums. The control moments, obtained in explicit form, ensure asymptotic stability of permanent rotation of the mechanical system (gyrostat) in question, with respect to the phase coordinates of the solid, as well as minimization of a certain functional of integral type.