Water hammer caused by the closing or opening of valves during pipeline operation and the condensation-induced water hammer phenomenon will occur during steam-water direct condensation in the pipeline system of a power station. The existence of this effect seriously threatens the safe operation of pipelines. In this study, a theoretical and numerical analysis of the ultimate bearing capacity of pipelines under water hammer was carried out. First, a mechanical model of X80 pipelines under water hammer was established. Then, based on the stress function method, an analytical solution of the pipeline under water hammer was derived. Next, the ultimate bearing capacity of pipelines under water hammer was explored based on the Zhu-Leis criterion. Finally, to verify the accuracy of the proposed method, we performed finite-element analysis for the radial, hoop, and axial stresses of the pipe under the action of water hammer, and found that the hoop stress is the main cause of failure under the action of water hammer. The results show that compared with the finite-element method, the prediction error is less than 3%, which can meet the requirements of calculation accuracy. This study provides a reference for the evaluation of pipeline integrity and a novel idea for the ultimate bearing capacity of pipelines under water hammer.