This paper discusses a real-time obstacle avoidance algorithm and its implementation for an underactuated flat-fish type autonomous underwater vehicle (AUV) in 3D space. The algorithm has been developed using multi-point potential field (MPPF) method and its real-time testing is carried out using hardware-in-loop (HIL) simulations. In MPPF method, a region of predefined radius on a hemisphere in the positive x-axis around the bow of an AUV is discretized into equiangular points with centre as the current position. By determining the point at which the minimum total potential exists, the vehicle can be moved towards that point. Here the analytical gradient of the total potential function is not calculated as it is not essentially required for moving the vehicle to the next position. The MPPF method is interfaced with dynamic model of an underactuated flat-fish type AUV and it is tested and verified using HIL simulation tool. The details of the dynamics of AUV, MPPF method and its implementation, development of HIL test bench and the simulation results are presented in this paper. The results show that the proposed MPPF method is very effective for obstacle avoidance in 3D space and can be used in the real-time control of the AUV.