The problem of operating freeze drying of pharmaceutical products in vials placed in trays of a freeze dryer to remove free water (in frozen state) at a minimum time was formulated as an optimal control problem. Two different types of freeze dryer designs were considered. In type I freeze dryer design, upper and lower plate temperatures were controlled together, while in type II freeze dryer design, upper and lower plate temperatures were controlled independently. The heat input to the material being dried and the drying chamber pressure were considered as control variables. Constraints were placed on the system state variables by the melting and scorch temperatures during primary drying stage. Necessary conditions of optimality for the primary drying stage of freeze drying process in vials are derived and presented. Furthermore, an approach for constructing the optimal control policies that would minimize the drying time for the primary drying stage was given. In order to analyze optimal control policy for the primary drying stage of the freeze-drying process in vials, a rigorous multi-dimensional unsteady state mathematical model was used. The theoretical approach presented in this work was applied in the freeze drying of skim milk. Significant reductions in the drying times of primary drying stage of freeze drying process in vials were obtained, as compared to the drying times obtained from conventional operational policies.