In order to ensure the safe construction and operation of the tunnel excavation near a goaf, based on the dynamic numerical analysis, we redeveloped the FLAC3D numerical simulation software using FISH programming to investigate the safety distance and energy evolution mechanism of the deep tunnel construction of an actual project. The results show that according to the different safety distances between the tunnel and the side goaf, the tunnel structure is divided into dangerous zone, influenced zone and safe zone. The relationship between the cumulative horizontal energy and stress ratio can be divided into three stages, which are acceleration, average stability and deceleration, and the energy evolution of the three stages can also reflect the damage and failure mechanism inside the surrounding rock. Moreover, the measured field vibration velocity curve shows that when the safety distance is 1 D, the goaf has limited influence on the stability of the tunnel, and the construction of the side-crossing section of the tunnel is safe on the whole and meets the safety requirements. Therefore, the optimal safety distance between the tunnel and the goaf is about the same as the tunnel span.