The Yunkai Magmatic Arc (YKMA) is located southwest of the South China Block. It has experienced the amalgamation, splitting, and intracontinental orogeny caused by multistage tectonic thermal events. It is also a concentrated area of strong earthquakes in South China. On 12 October 2019, the Beiliu M5.2 earthquake occurred in the hinterland of the YKMA. To reveal the deep electrical structure of the YKMA and the seismogenic environment of the Beiliu earthquake, 101 high-quality data from the magnetotelluric (MT) survey points were acquired. The deep electrical structure images were obtained by three-dimensional electromagnetic inversion imaging. The results indicated that the deep part of the hinterland of the YKMA is characterized by a mushroom-shaped electrical structure composed of ultra-high resistance (R1, with a resistivity value exceeding 10,000 Ωm) and sub-high resistance (R2, with a resistivity value of about 1,000–10,000 Ωm) bodies. The epicenter of the Beiliu M5.2 earthquake was located in R1, close to the contact region between R1 and R2. There are broad low resistivity zones on the southeast and northwest sides of the YKMA. The low resistivity zones is considered to be correspond to the deep extension of the Wuchuan-Sihui and Hepu-Beiliu brittle-ductile shear zones, respectively. The brittle-ductile shearing of the boundary zones and the oblique upwelling of deep mantle-derived magma from the Leiqiong region are the main reasons for the activation of faults and the activity of moderate and strong earthquakes in the YKMA. In this geodynamic environment, local stress and strain accumulation easily occur in the brittle high resistivity body (R1). When the strain energy accumulation exceeded the threshold value that the rock could withstand, new fracture dislocations occurred in the weak region where R1 and R2 contact, which finally resulted in the 2019 Beiliu M5.2 earthquake.