A very challenging issue in robot navigation or path planning in an unknown environment is to find a globally optimal path from the start to the target point at the same time avoid collisions. This paper presents a new sensor-based online method for generating collision-free optimal path for mobile robots to take a target amidst static obstacles. It is assumed that, target is static and the location of obstacles is completely unknown for robot and all of these materials will be calculated online. Although the area that is under vision of robot’s sensor is confined, we have to consider an inevitable assumption that target is detectable by robot in everywhere. Proposed algorithm to avoid colliding the obstacles in its way toward target, detects a short and feasible paths by utilizing an innovative and effective method. Following that, shortest of them to will be chosen for navigation. There are different important factors which are considered in robot motion planning problems. First, required time for robot’s action in unpredicted circumstances that the running time of the used algorithm plays a major role in this term. Second, the length of traveled path from start point to target point that represents the efficiency of exploited algorithm for leading the robot. The presented algorithm of this paper has proved its efficiency in both of mentioned issues. Simulation results show that traveled path has the least length and the running time is remarkably less than other presented algorithms until now. In addition, the effectiveness of presented algorithm in complex situation is discernible. These results prove that the presented novel and effective robot navigation algorithm is very suitable for real-time navigation in complex environments.