Here, a two-phase algorithm based on integrating particle swarm optimization (PSO) with modified hybrid genetic algorithm (MHGA) is proposed for solving the associated nonlinear programming problem of a nonlinear optimal control problem. In the first phase, PSO starts with a completely random initial swarm of particles, where each of them contains two random matrices in time nodes. After phase 1, to achieve more accurate solutions, the number of time nodes is increased. The values of the associated new control inputs are estimated by linear or spline interpolations using the curves computed in the phase 1. In addition, to maintain the diversity in the population, some additional individuals are added randomly. Next, in the second phase, MHGA, starts by the new population constructed by the above procedure and tries to improve the obtained solutions at the end of phase 1. MHGA combines a GA with a successive quadratic programming, SQP, as a local search. Finally, we implement the proposed algorithm on some well-known nonlinear optimal control problems. The numerical results show that the proposed algorithm can find almost better solution than other proposed algorithms.