Phase unwrapping is one of the key problems in reconstructing the digital elevation model of a scene from its interferometric synthetic aperture radar (InSAR) or interferometric synthetic aperture sonar (InSAS) data. In this letter, we propose a quality-guided and local minimum discontinuity based phase unwrapping algorithm, which enhances the precision of the unwrapped result by local minimum discontinuity optimization in low quality areas, and still keeps a high efficiency. The new algorithm can be divided into two steps. Firstly, the quality-guided phase unwrapping algorithm is performed on the original wrapped phase image, which helps to remove all the discontinuities caused by the wrapping operation quickly, but tends to spread the unwrapped errors in low quality areas. Secondly, the initial unwrapped result is divided into high and low quality areas according to its quality map, and the minimum discontinuity optimization process is performed in the low quality areas of the initial unwrapped result, which helps to remove the remaining improving loops defined as a loop with more positive jumps than negative ones. This prevents the unwrapped errors spreading from low quality areas to high quality areas and accelerates the optimization process by restricting the optimization place in low quality areas. Tests performed on InSAR and real InSAS data confirm the accuracy and efficiency of the proposed algorithm.