Officials said the soldier who fled Thursday was not fired upon. South Korean soldiers later fired 20 warning shots at North Korean border guards who were searching for the defector, which was followed 40 minutes later by gunfire in the North, the Joint Chiefs of Staff said.

More than 30,000 North Koreans have fled to South Korea since a famine killed at least a million people in the North in the 1990s. The country has recently been the subject of a tightening grip of sanctions that have curbed exports that provide urgently needed revenue, and it has been struggling with the impact of a drought that has reduced agricultural yields.

But it is extremely rare for people to flee across the demilitarized zone. The 2.5-mile-wide DMZ, considered the most heavily fortified border in the world, is guarded by minefields, sentry posts and tall fences topped with barbed wire, some electrified.

The soldier’s defection to South Korea on Thursday was the fourth this year, and the gunfire over the episode is certain to raise tensions on the Korean Peninsula just as hopes have grown for a thaw in relations between the South and North.

South Korean officials have recently held out the possibility that they might be willing to push back the timing of planned joint military exercises with the United States to reduce tensions.