The Orion Nebula Cluster (ONC) is an excellent example for understanding the formation of star clusters. Recent studies have shown that ONC has three distinct age populations and anisotropy in velocity dispersions, which are key characteristics for understanding the formation history of the ONC. In this study, we perform a smoothed-particle hydrodynamics/$N$-body simulation of star cluster formation from a turbulent molecular cloud. In this simulation, stellar orbits are integrated using a high-order integrator without gravitational softening; therefore, we can follow the collisional evolution of star clusters. We find that hierarchical formation causes episodic star formation that is observed in the ONC. In our simulation, star clusters evolve due to mergers of subclumps. The mergers bring cold gas with the clumps into the forming cluster. This enhances the star formation in the cluster centre. The dense cold gas in the cluster centre continues to form stars until the latest time. This explains the compact distribution of the youngest stars observed in the ONC. Subclump mergers also contribute to the anisotropy in the velocity dispersions and the formation of runaway stars. However, the anisotropy disappears within 0.5 Myr. The virial ratio of the cluster also increases after a merger due to the runaways. These results suggest that the ONC recently experienced a clump merger. We predict that most runaways originated from the ONC have already been found, but walkaways have not. Comment: 15 pages, 21 figures, and 3 tables, accepted for MNRAS