During the previous years, the number of researchers who discussed the field of path planning algorithms has increased. In this paper, a proposed hybrid technique for path planning based on the benefits of sampling-based algorithms and heuristic path planning algorithms was enhanced. Rapidly-exploring Random Tree star (RRT*) was used to generate the candidate nodes that represent a collision-free path. These candidate nodes were applied to the Particle Swarm Optimization (PSO) algorithm to generate the shortest and the smoothest path planning (the optimal path planning) for the mobile robot. The RRT*PSO algorithm was applied in two scenarios (static and dynamic environments) with a workspace of [500×500] cm using MATLAB 2021a. In the static environment, a workspace full of obstacles was chosen to find the shortest collision-free path. In addition, a reference path equation was found to calculate the reference linear and angular velocities of the mobile robot as well as the linear and angular velocities of the right and left wheels. In this work, the suggested hybrid RRT*PSO algorithm improves path length 34.27% compared to the A* algorithm and the fuzzy analytic hierarchy process (A*-FAHP hybrid) algorithm and 0.35% compared to the Self-adaptive evolutionary game-based particle swarm optimization (SAEGBPSO) algorithm. In the dynamic environment, an algorithm named (contour path down and contour path up) was suggested to avoid collisions with dynamic obstacles. By using this suggested algorithm, the reference linear and angular velocities of the mobile robot as well as the linear and angular velocities of the right and left wheels were calculated to obtain a smooth path followed and free-navigation with dynamic obstacles in an environment.