Safe trajectory planning of unmanned aerial vehicles (UAVs) has drawn significant attention. For avoiding obstacles, the two prevailing methods of distance penalty and convex polyhedra confinement ignore the flight velocity, aggressive maneuvering increases the risk of collision. Other approaches ensure safety by limiting the flight speed, leading to conservative and slow trajectories. This paper presents a motion planning method that ensures flexible maneuverability and a high level of UAV safety in unknown complex environments. Firstly, an improved path planning method considering safety and search efficiency is proposed to generate discrete primitives. By representing the confident flight area with ball-shaped areas expected no obstacles included, the safe region constraint is designed and incorporated into the first-stage optimization with the low-order kinematic model. Subsequently, an agile maneuvering approach with environmental adaptability is integrated into the second-stage optimization with the high-order kinematic model. This approach can effectively adjust the agile flight according to the obstacle distribution and motion velocity. Simulations and real-world experiments are conducted to demonstrate the robustness and effectiveness of the presented approach. Moreover, benchmark comparison manifests that the proposed method outperforms the cutting-edge methods from the aspects of the perception uncertainty adaptation and flight safety.