Summary With the deepening of exploration and development of oil and gas resources, more complex oil and gas reservoirs have been found, and oil and gas well drilling has gradually developed to ultradeep (>8000 m). In the oil and gas exploration and development of deep and ultradeep wells, a small-size borehole is usually used to uncover the target layer. In the drilling stage, the annular space gap of slimhole construction is small, the pressure difference is large, and the tripping fluctuation pressure is large; therefore, overflow is easy to occur. Because the upward channeling speed after overflow is fast, the pressure fluctuation caused by shut-in is large, and the requirements for well control are high, making it very important to study the shut-in mode after drilling overflow and the fluctuation of annulus pressure to ensure the safety of ultradeep well drilling. However, the current research on shut-in mode only focuses on changing the length of shut-in time and does not consider the operation steps of closing different components. It is obviously not rigorous to simplify semisoft shut-in and soft shut-in into a hard shut-in process with a long time. In this paper, the pressure wave velocity model and transient flow model of multiphase flow in the annulus are established. The shut-in process of different wellhead components is considered for the first time, the corresponding wellhead opening function is constructed, and the effects of different well shut-in methods on annulus pressure distribution and water hammer effect are studied. Some conclusions can be drawn: The annulus pressure wave velocity aam decreases rapidly with the increase of void fraction and decreases gradually with the increase of solid particle concentration. After hard shut-in, the wellhead pressure increases rapidly and fluctuates periodically. The shorter the shut-in time, the greater is the wellhead pressure. The displacement of drilling fluid has little influence on the pressure peak but has a great influence on the amplitude of pressure fluctuation. When the annulus pressure rises, the casing bulges outward to produce additional tension, while the drillpipe shrinks inward to produce additional pressure. When the annulus pressure drops, the casing shrinks inward to produce additional pressure, while the drillpipe bulges outward to produce additional tension. During soft shut-in, the closing time of the blowout preventer (BOP) has a great impact on the annulus pressure of the wellhead. When the shut-in time is short, the pressure rises instantaneously and fluctuates violently and the cycle is short; during semisoft shut-in, the larger the opening of the throttle valve, the smaller is the fluctuating pressure of the wellhead when the BOP is closed. When the throttle valve is closed after the BOP is closed, then the larger the opening of the throttle valve, the greater will be the fluctuating pressure. With the calculation and discussion of wellbore stress distribution during shut-in of an overflow well in this paper, we hope to provide reference for two groups of people mainly. For one thing, it can offer a new idea, calculation method, and meaningful conclusion to other researchers who are studying in this area. For another, it will help engineers making decisions when overflow occurs.