A new formulation of the particle filter for nonlinear filtering is presented, based on concepts from optimal control, and from the mean-field game theory framework of Huang et. al. . The optimal control is chosen so that the posterior distribution of a particle matches as closely as possible the posterior distribution of the true state, given the observations. In the infinite-N limit, the empirical distribution of ensemble particles converges to the posterior distribution of an individual particle. The cost function in this control problem is the Kullback-Leibler (K-L) divergence between the actual posterior, and the posterior of any particle. The optimal control input is characterized by a certain Euler-Lagrange (E-L) equation. A numerical algorithm is introduced and implemented in two general examples: A linear SDE with partial linear observations, and a nonlinear oscillator perturbed by white noise, with partial nonlinear observations.