The path planning problem is the core issue in the automatic guided vehicle (AGV) sorting system. The current AGV sorting system has the following characteristics: (1) a great number of AGVs; (2) dynamic sorting of tasks; and (3) two-stage tasks involving transporting express packages and then leaving the sorting area. Therefore, existing path planning methods face challenges in terms of achieving timeliness and optimality. In this paper, the path planning problem of the AGV sorting system in a mesh topology area is modeled. A Driving Line-based Two-Stage (DLTS) path planning algorithm is proposed. First, to avoid conflicts among AGVs with different driving directions, time–space resources are divided according to the driving line mechanism, which specifies the driving direction, possible planned locations and specific driving rules. Second, we propose an incremental search method to plan continuous paths for two-stage tasks while simultaneously avoiding conflicts among AGVs moving in the same direction. Finally, we verify the effectiveness of our method in terms of real-time and optimal performance through simulation experiments.