Purpose: The magnetic resonance imaging (MRI)-Linac system combines a MRI scanner and a linear accelerator (Linac) to realize real-time localization and adaptive radiotherapy for tumors. Given that the Australian MRI-Linac system has a 30-cm diameter of spherical volume (DSV) with a shimmed homogeneity of ±4.05 parts per million (ppm), a gradient nonlinearity (GNL) of <5% can only be assured within 15 cm from the system's isocenter. GNL increases from the isocenter and escalates close to and outside of the edge of the DSV. Gradient nonlinearity can cause large geometric distortions, which may provide inaccurate tumor localization and potentially degrade the radiotherapy treatment. In this study, we aimed to characterize and correct the geometric distortions both inside and outside of the DSV. Methods: On the basis of phantom measurements, an inverse electromagnetic (EM) method was developed to reconstitute the virtual current density distribution that could generate gradient fields. The obtained virtual EM source was capable of characterizing the GNL field both inside and outside of the DSV. With the use of this GNL field information, our recently developed “GNL-encoding” reconstruction method was applied to correct the distortions implemented in the k-space domain. Results: Both phantom and in vivo human images were used to validate the proposed method. The results showed that the maximal displacements within an imaging volume of 30 cm × 30 cm × 30 cm after using the fifth-order spherical harmonic (SH) method and the proposed method were 6.1 ± 0.6 mm and 1.8 ± 0.6 mm, respectively. Compared with the fifth-order SH-based method, the new solution decreased the percentage of markers (within an imaging volume of 30 cm × 30 cm × 30 cm) with ≥1.5-mm distortions from 6.3% to 1.3%, indicating substantially improved geometric accuracy. Conclusions: The experimental results indicated that the proposed method could provide substantially improved geometric accuracy for the region outside of the DSV, when comparing with the fifth-order SH-based method.