Using the methods of the optimal control theory, the problem of determining the optimal technological mode of gas deposits’ exploitation under the condition of their depletion by a given point in time is solved. This task is of particular interest for the exploitation of offshore fields, the activity of which is limited by the service life of the field equipment. The considered problem is also of certain mathematical interest as an objective of optimal control of nonlinear systems with distributed parameters. The usefulness and importance of solving such problems are determined by the richness of the class of major tasks that have a practical result. As an optimality criterion, a quadratic functional characterizing the conditions of reservoir depletion is considered. By introducing an auxiliary boundary value problem, and taking into account the stationarity conditions for the Lagrange functions at the optimal point, a formula for the gradient of the minimized functional is obtained. To obtain a solution to this specific optimization problem, which control function is sought in the class of a piecewise continuous and bounded function with discontinuities of the first kind, the Pontryagin’s maximum principle is subjected. The calculation of the gradient of the functional for the original and adjoint problems with partial differential equations is carried out by the method of straight lines. The numerical solution of the problem was carried out by two methods – the method of gradient projection with a special choice of step and the method of successive approximations. Despite the incorrectness of optimal control problems with a quadratic functional, the gradient projection method did not show a tendency to «dispersion» and gave a convergent sequence of controls.