North Korean troops fired on a fellow soldier who was defecting to South Korea on Monday across the heavily armed border dividing the countries, South Korean officials said, amid heightened tensions over the North’s nuclear weapons program. The soldier was shot but succeeded in reaching the South, its military said in a statement. The North Korean soldier defected through Panmunjom, a village that straddles the border between the two Koreas. Alerted by gunshots, South Korean guards found the North Korean soldier about 55 yards south of the border line that bisects Panmunjom. He was taken to a hospital with gunshot wounds to an elbow and shoulder, South Korean officials said. His defection took place while a joint naval exercise involving three American aircraft carriers was being conducted in waters off South Korea’s east coast. It was the first time in a decade that the United States Navy had mobilized three carrier groups in the same drill in the western Pacific, and it represented the show of force that President Trump has said Americans “hope to God we never have to use” against North Korea. North Korea has remained defiant, calling Mr. Trump a “dotard” again on Saturday and insisting that it will never give up its pursuit of nuclear weapons. The defector drove a vehicle toward the border line inside Panmunjom, and then left the vehicle, running south while he was fired upon by other North Korean soldiers, according to the American-led United Nations Command, which oversees the 1953 armistice that halted the Korean War. He took cover near a building on the southern side of the Joint Security Area in Panmunjom before South Korean and American troops came to his aid and took him to a hospital, the command said in a statement. The Joint Security Area, which is 35 miles north of Seoul, the capital, was established after North Korea and its Communist ally China signed the armistice with the United Nations Command, which fought on South Korea’s behalf. The area is the only place along the border where troops from North and South Korea face off, separated from each other by only a few feet. A North Korean soldier last defected at the heavily guarded location in 2007. More than 30,000 North Koreans have fled to the South since a widespread famine hit the impoverished North in the late 1990s. Nearly all of them have traveled through China. But a few North Korean soldiers and civilians have defected by crossing the 2.5-mile-wide demilitarized zone, which is guarded by minefields, sentry posts and tall fences topped with barbed wire, some electrified. In 2012, a North Korean soldier scaled three barbed-wire fences to defect to the South. That same year, another North Korean soldier fled across the border after killing his platoon and squadron leaders. In 2015, after walking across the border, a North Korean soldier told South Korean investigators that he was fleeing widespread beatings and other abuse within his military barracks. The demilitarized zone is one of the world’s most heavily armed borders. Guards on both sides stay alert against possible intruders or defectors.