In five-axis CNC machining, abrupt tool axis direction shifts and over-limit rotary axis motions trigger vibration, accuracy degradation and low processing efficiency. To smooth tool axis motion and realize feed rate synchronization, this paper proposes an innovative greedy search-based tool axis optimization algorithm, which integrates rotary axis motion constraints with an asymmetric seven-segment S-curve acceleration and deceleration scheme to construct a complete five-axis machining trajectory optimization strategy. Numerical simulation results show that the proposed method reduces the average tool orientation vector variation rate to 0.018, with a maximum reduction of 85.48% compared with conventional G01 linear interpolation. The 90th percentile of the angle between adjacent tool orientation vectors is only 2.01°, the median feed rate reaches 29.20 mm/s, and rotary axis angular velocity complies with machine tool constraints throughout machining; total processing time falls to 81.34 s, boosting machining efficiency by 35.24%. Even in high-curvature regions, the average feed rate remains 26.89 mm/s, directional angle error is controlled within 0.53°, and no angular velocity limit violation occurs. This method effectively eliminates trajectory mutations and feed rate fluctuations in five-axis machining through geometric and kinematic optimal smoothing, delivering an effective technical solution for machining complex surface parts.