On SOL2017-09-06 solar active region 12673 produced an X9.3 flare which is regarded as largest to occur in solar cycle 24. In this work we have preformed a magnetohydrodynamic (MHD) simulation in order to reveal the three-dimensional (3D) dynamics of the magnetic fields associated with the X9.3 solar flare. We first performed an extrapolation of the 3D magnetic field based on the observed photospheric magnetic field prior to the flare and then used it as the initial condition for an MHD simulation. Consequently, the simulation showed a dramatic eruption. In particular, we found that a large coherent flux rope composed of highly twisted magnetic field lines is formed during the eruption. A series of small flux ropes are found to lie along a magnetic polarity inversion line prior to the flare. Reconnection occurring between each small flux rope during the early stages of the eruption forms the large and highly twisted flux rope.Furthermore, we found a writhing motion of the erupting flux rope. The understanding of these dynamics is important in increasing the accuracy of space weather forecasting. We report on the detailed dynamics of the 3D eruptive flux rope and discuss the possible mechanisms of the writhing motion.