In this research, an optimal real-time trajectory planning method is proposed for autonomous ground vehicles in case of overtaking a moving obstacle. When an autonomous vehicle detects a moving vehicle ahead of it in a proper speed and distance and the braking is not efficient due to the lost of its kinematic energy, the autonomous vehicle decides to overtake the obstacle by performing a double lane-change maneuver. A two-phase nonlinear optimal problem is developed for generating the path for the overtaking maneuver. The cost function of the first phase is defined in such a way that the vehicle approaches the moving obstacle as close as possible. Besides, the cost function of the second phase is defined as the minimization of the sum of the vehicle lateral deviation from the reference path and the rate of steering angle during the overtaking maneuver while the lateral acceleration of the vehicle does not exceed a safe limit. For the real-time path planning of a vehicle with high speed, the result of solving the optimal path planning are stored in the look-up table form for offline use. A full nonlinear vehicle modeled in CarSim software is used for path tracking simulation. The simulation results show that the generated path for the autonomous vehicle satisfies all the vehicle dynamics constraints, therefore it is applicable for a real autonomous vehicle.