In recent years, marine engineers have increasingly relied on multiship collaborative work to complete complex tasks at sea and improve maritime transport efficiency. Ship formation significantly contributes to the maintenance of stability during multiship-coordinated operations, but establishing the formation structure while ensuring the safety of each ship remains challenging. Therefore, this study proposes an improved leader-follower-based formation algorithm as a solution to this issue. First, the fast marching square method was used for global static path planning. The leader-follower formation control method then enabled the path tracking of the follower ship to the leader ship. Finally, an improved artificial potential field method was used for local collision avoidance, and virtual obstacles were added to improve the situation in which the ship probably entered a local minimum point. The experimental results revealed that the proposed algorithm could plan a route with time, smoothness, and safety advantages for the formation leader and quickly form a stable formation. Notably, the ship can quickly initiate collision avoidance operations when it encounters an obstacle posing a collision risk.INDEX TERMS Artificial potential field method, fast marching square method, formation of ships, leaderfollower method, local collision, path planning.