In this paper a necessary condition is given for a real-valued function f to attain a maximum at a point b subject to the condition XES, where S is given as an intersection of a finite number of sets in an n-dimensional Euclidean space. It is shown that well-known necessary conditions in mathematical programming, like the Lagrange multipliers theorem and results ofF. John, Mangasarian and Fromovitz, are immediate consequences of this general condition. The result is also used to derive ageneral necessary condition for discrete-time optimal control problems, which contains the results of Halkin (discrete maximum principle), Jordan and Polak, and Canon, Cullum and Polak as special cases. As a final application of the necessary condition a simple proof of the Pontryagin maximum principle for continuous-time control problems is given.