We address the problem of capacity integration in a port cluster under demand uncertainty, which involves determining the optimal capacity investment and exit decisions for the ports in a port cluster over multiple stages. Based on real option theory, we first investigate the optimal investment and exit decisions for a single incapacitated port without integration under uncertainty. Second, we present the optimal scale of a port cluster based on the continuous approximation-based approach in facility location theory, which offers an optimization objective for capacity integration in an existing port cluster. Third, we build a multistage capacity investment and exit (MCIEI) model to minimize the gap between the social welfare under an existing port cluster and the social welfare at the optimal scale of a port cluster. In addition, we present a dynamic programming-based pattern search algorithm (DP-GPS) to solve the proposed model. Finally, the optimal investment and exit decisions for a single port are derived from the case of Chinese seaports. The results indicate that when the potential maritime demand of the catchment area is above a threshold, the optimal investment capacity increases linearly in the potential maritime demand while the optimal exit capacity decreases linearly in the potential maritime demand. Furthermore, the MCIEI model and the corresponding DP-GPS algorithm are verified with respect to the Liaoning port cluster in mainland China. The numerical results illustrate that the Jinzhou and Dalian Ports should adopt exit decisions in the optimal capacity integration scheme, while the Yingkou and Dandong Ports should opt to invest. Our research outcomes can help guide port integration in port clusters and further establish resource-saving ports in coastal regions.