South Korea decided on Friday against scrapping a critical military intelligence-sharing pact with Japan, in a dramatic 11th-hour U-turn that will come as a relief to the United States. The pact was due to expire at midnight amid a sharp deterioration in ties between the two US allies has alarmed Washington as it seeks to curb the threat from nuclear-armed North Korea. But after a flurry of last-ditch diplomacy, Seoul announced it would "conditionally" suspend the expiry of the agreement with just six hours left on the clock. Kim You-geun, a national security official at Seoul's presidential Blue House, confirmed the accord, known as GSOMIA, would not be allowed to lapse at midnight. "The Japanese government has expressed their understanding," he said. However, he warned that the pact could still "be terminated at any time". Japan's Foreign Minister Toshimitsu Motegi stressed the pact was "important," adding: "Given the current state of security conditions in this region, I believe South Korea made this decision from a strategic standpoint." He said officials were working to hold bilateral talks with his South Korean counterpart Kang Kyung-wha on the sidelines of a meeting of G20 foreign ministers in Nagoya. Seoul had announced the scrapping of the pact in August as a trade row sparked by historical disputes between the countries spiralled into one of their worst diplomatic spats in years. South Korea and Japan are both major US allies, democracies and market economies faced with an overbearing China and wayward, nuclear-armed North Korea. But their relationship is heavily coloured by territorial and historical disputes stemming from Japan's bitterly-resented 35-year colonial rule over the peninsula, including the use of wartime sex slaves and forced labour. The General Security of Military Agreement, signed in 2016, enabled the two US allies to share military secrets, particularly over North Korea's nuclear and missile capacity. The United States had frequently urged its two main allies in the region to bury the hatchet, stressing that the only countries to benefit from the row were North Korea and China. US officials have admitted privately that poor relations between Seoul and Tokyo are complicating diplomacy in the region. Scrapping the pact would have been "a huge setback for one of the pillars of East Asia's security that Japan, South Korea and the United States have established", said Kenichiro Sasae, a former top Japanese foreign minister official and ambassador to the US. US Defence Secretary Mark Esper said on a recent trip to Asia that the only beneficiaries from the pact being scrapped would be North Korea and China, and urged the two allies to "sit down and work through their differences". South Korea had promised to continue sharing secrets via the United States as a third party, but this had raised concerns about efficiency in an emergency situation. Seoul had renewed the pact every year and its sudden decision to scrap it came as a surprise as most thought the country would maintain security co-operation with Japan despite the ongoing row. However, ties were affected by a string of South Korean court rulings ordering Japanese firms to compensate forced labour victims infuriated Japan. Relations were further hit in July after Tokyo said Seoul was not properly handling sensitive imports and took the country off a list of nations that enjoyed streamlined export control procedures. This enraged South Korea, which hit back with similar moves, culminating in the decision to end the military pact. Japan says a 1965 treaty that normalised relations with a significant financial contribution effectively settled all reparation claims from its wartime atrocities. "The biggest issue and the root problem is the issue related to former labourers from the Korean peninsula," Mr Motegi told reporters. "We continue to strongly demand South Korea to remedy as soon as possible the current situation that violates the international law."