Understanding the evolving governance mechanisms in megaprojects is crucial for reducing transaction costs and ensuring project success. However, previous literature primarily discusses the results of selecting governance mechanisms at different phases, with little research exploring the reasons behind these choices. To fill this gap, this article addresses the question of how to select effective governance mechanisms at different phases from the perspective of contractor alliances, based on transaction cost economics (TCE). We employ a longitudinal exploratory case study method to analyse the governance mechanism selection process across three phases (i.e. contractor alliance formation phase, shield construction phase and crisis response phase) of a large infrastructure project in China. The results indicate that the likelihood of opportunistic behaviour, uncertainty and the duration of the phase jointly explain the reasons for selecting specific governance mechanisms. Additionally, we also find that contractual governance, network governance and hierarchical governance are typically complementary in multiple phases of megaprojects. This article provides valuable managerial insights for future governance practices in megaprojects.