A heuristic nonlinear model predictive controller is proposed, based on the gravitational search algorithm. The proposed method models a constrained nonlinear model predictive control problem in the form of a dynamic optimization and uses a set of virtual particles, moving within the search space, to find the best control sequence in an online manner. Particles affect the movement of each other through the gravitational forces. The optimality of the points, experienced by the particles, is evaluated by a cost function. This function reduces the tracking error, control effort, and control chattering. The better control sequence a particle finds, the more mass is assigned to that particle. Therefore, it will apply more gravitational force to the other particles and will absorb them more strongly. Stability of the new controller is investigated. Finally, performance of the controller is evaluated in two nonlinear benchmark problems as well as an experimental attitude control of a quadrotor as a nonlinear multi‐input multi‐output system with input constraints. Results confirm successful performance of the proposed controller.