The paper presents a method for solving the problem of optimal control of a chemical process in the presence of terminal constraints based on the application of artificial immune systems. The formulation of the problem of optimal control of a chemical process in which the constraints on the control parameter and phase variables are given is formulated. An algorithm for solving this problem based on the penalty method and artificial immune systems is given. The penalty method allows to reduce the problem with terminal constraints to the problem without constraints by changing the optimality criterion. The new optimal control problem without terminal constraints is solved by the method of artificial immune systems. The described methodology is tested on the example of an industrially significant process of phthalic anhydride production. A mathematical description of the process, which is a system of ordinary differential equations, is given. The problem of search of optimal temperature regime with terminal constraints is formulated. As a result of calculations, the optimal temperature regime and the corresponding optimal concentrations of substances are determined. At the same time, the restrictions on the concentration value of the reaction by-product and the conversion of substances at the end of the reaction are fulfilled. It is shown that the solution of the optimal control problem with terminal constraints for the process of phthalic anhydride production satisfies the constraints of the problem and provides the highest value of the concentration of the target reaction product.