In this paper, we present a system capable of automatically steering bevel tip flexible needles under ultrasound guidance toward stationary and moving targets in gelatin phantoms and biological tissue while avoiding stationary and moving obstacles. We use three-dimensional (3D) ultrasound to track the needle tip during the procedure. Our system uses a fast sampling-based path planner to compute and periodically update a feasible path to the target that avoids obstacles. We then use a novel control algorithm to steer the needle along the path in a manner that reduces the number of needle rotations, thus reducing tissue damage. We present experimental results for needle insertion procedures for both stationary and moving targets and obstacles for up to 90 mm of needle insertion. We obtained a mean targeting error of $$0.32\pm 0.10$$ 0.32 ± 0.10 and $$0.38\,\pm \,0.19$$ 0.38 ± 0.19 mm in gelatin-based phantom and biological tissue, respectively. The achieved submillimeter accuracy suggests that our approach is sufficient to target the smallest lesions ( $$\phi $$ ϕ 2 mm) that can be detected using state-of-the-art ultrasound imaging systems.