Robots are now among us and even though they compete with human beings in terms of performance and efficiency, they still fail to meet the challenge of performing a task optimally while providing strict motion safety guarantees. It is therefore necessary that the future generation of robots evolves in this direction. Generally, in robotics state-of-the-art approaches, the trajectory optimization and the motion safety issues have been addressed separately. An important contribution of this paper is to propose a motion planning method intended to simultaneously solve these two problems in a formal way. This motion planner is dubbed PassPMP-PSO. It is based on a periodic process that interleaves planning and execution for a regular update of the environment’s information. At each cycle, PassPMP-PSO computes a safe near-optimal partial trajectory using a new tree encoding technique based on particle swarm optimization (PSO). The performances of the proposed approach are firstly highlighted in simulation environments in the presence of moving objects that travel at high speed with arbitrary trajectories, while dealing with sensors field-of-view limits and occlusions. The PassPMP-PSO algorithm is tested for different tree expansions going from 13 to more than 200 nodes. The results show that for a population between 20 and 100 particles, the frequency of obtaining optimal trajectory is 100% with a rapid convergence of the algorithm to this solution. Furthermore, an experiment-based comparison demonstrates the performances of PassPMP-PSO over two other motion planning methods (the PassPMP, a previous variant of PassPMP-PSO, and the input space sampling). Finally, PassPMP-PSO algorithm is assessed through experimental tests performed on a real robotic platform using robot operating system in order to confirm simulation results and to prove its efficiency in real experiments.