In this research, an optimal real-time trajectory planning method is proposed for autonomous ground vehicles in case of overtaking a moving obstacle. The autonomous vehicle decides to overtake the obstacle when detects a moving vehicle in a proper speed and distance ahead it and the braking is not efficient due to the lost of kinematic energy of vehicle. The path for the overtaking maneuver is generated by a two-phase optimal path planning problem. The cost function of the first phase is defined in such a way that the vehicle approaches the obstacle as close as possible. In the second phase, the cost function is defined as sum of the vehicle lateral deviation from the reference path and the rate of steering angle. At the same time, the lateral acceleration of the vehicle must not exceed a specified limit. An adaptive cruise control with the offline path planning base on the optimization results are used for designing the real-time path trajectory planning for overtaking the moving obstacle. A full nonlinear vehicle model in CarSim software is used for path tracking simulation. The simulation results show that the generated path for the autonomous vehicle satisfies all vehicle dynamics constraints and hence is applicable for a real autonomous vehicle.