We tackle a nonlinear optimal control problem for a stochastic differential equation in Euclidean space and its state-linear counterpart for the Fokker-Planck-Kolmogorov equation in the space of probabilities. Our approach is founded on a novel concept of local optimality surpassing Pontryagin's minimum, originally crafted for deterministic optimal ensemble control problems. A key practical outcome is a rapidly converging numerical algorithm, which proves its feasibility for problems involving Markovian and open-loop strategies.