Providing an accurate trajectory in an underwater scene is challenging for visual odometry due to weak texture and varying illumination. In this article, we propose a novel underwater visual-inertial odometry (VIO) with the unifying direct method and feature-based method. Our approach starts with a new rectification method for underwater images. The new underwater image rectification method separately eliminates water-air refraction distortion and lens distortion with an approximate single viewpoint (SVP) camera model. Meanwhile, a unified optimization method is used in our approach to obtain robust and highly accurate odometry results. This method jointly optimizes projection errors and photometric errors. Moreover, the robust data association processing, which combines <italic xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">keyframe</i> / <italic xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">keypoint</i> selection, <italic xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">keypoint</i> position prediction, and robust local optical flow, was designed in our approach. The robust data association processing greatly improves the success rate of <italic xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">keypoints</i> tracking. To evaluate the precision of underwater visual odometry, an underwater dataset with complete and highly accurate ground truth trajectories is provided in this work. The performance of our system is compared with other state-of-the-art algorithms on multiple datasets, including visual odometry datasets and our proposed underwater dataset. The evaluation results show that the proposed system can achieve better results than the state-of-the-art algorithms. Furthermore, the proposed system is validated on public natural underwater datasets to show the performance of the system in a real underwater environment. The qualitative results demonstrate that the proposed system can work well in the natural underwater environment.