SEOUL, South Korea — 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.