This paper studies three-dimensional (3D) straight line path following and obstacle avoidance control for an underactuated autonomous underwater vehicle (AUV) without lateral and vertical driving forces. Firstly, the expected angular velocities are designed by using two different methods in the kinematic controller. The first one is a traditional method based on Line-of-sight (LOS) guidance law, and the second one is an improved method based on model predictive control (MPC). At the same time, a penalty item is designed by using the obstacle information detected by onboard sensors, which can realize the real-time obstacle avoidance of the unknown obstacle. Then, in order to overcome the uncertainty of the dynamics model and the saturation of actual control input, the dynamic controller is designed by using sliding mode control (SMC) technology. Finally, in the simulation experiment, the performance of the improved control method is verified by comparison with two traditional control methods based on LOS guidance law. Since the constraint of an AUV’s angular velocities are considered in MPC, simulation results show that the improved control method uses MPC, and SMC not only improves the tracking quality of the AUV when switching paths near the waypoints and realizes real-time obstacle avoidance but also effectively reduces the mean square error (MSE) and saturation rate of the rudder angle. Therefore, this control method is more conducive to the system stability and saves energy.