Image copyright AFP Image caption Protesters outside the US embassy in Seoul called for an extension of the pact, known as GSOMIA

South Korea says it is to continue a military intelligence-sharing pact with Japan that had been threatened by a long-running dispute.

The move was welcomed by the US which had urged the two countries to settle their differences.

Seoul announced its decision on Friday, just hours before the pact was due to expire.

Tensions between South Korea and Japan go back decades but have recently led to a series of tit-for-tat measures.

The tensions have historical roots, and the two countries became embroiled in a deepening trade and diplomatic dispute this year.

The intelligence pact, known as GSOMIA (General Security of Military Information Agreement), allowed the two countries to share information about North Korea's military and nuclear activities directly with each other.

Without it, information would have had to go through their joint-allies in Washington, slowing the process down.

Image copyright Reuters/Kyodo Image caption Japanese PM Shinzo Abe welcomed the "strategic decision"

What has been announced?

In August, South Korea announced it would terminate the intelligence-sharing agreement and Japan removed South Korea's favoured trade partner status and imposed export controls on its electronics sector.

Earlier this month the leaders of the two countries briefly met at a summit in Bangkok, Thailand, to try to resolve their differences.

Then on Friday South Korea said it would "conditionally" suspend the expiry, with national security official Kim You-geun confirmed that the GSOMIA would not be allowed to lapse at midnight.

He said the Japanese government had "expressed their understanding" but warned that the agreement could still "be terminated at any time".

Japanese Prime Minister Shinzo Abe said bilateral relations were vital and that South Korea had made a "strategic decision" in sticking with the accord.

A US State Department spokeswoman welcomed the decision, saying: "This decision sends a positive message that like-minded allies can work through bilateral disputes."

What's the background?

The two countries share a complicated history. They have fought on and off since at least the 7th Century, and Japan has repeatedly tried to invade the peninsula since then.

In 1910, it annexed Korea, turning the territory into a colony. Resentment over this period, when many South Korean workers were forced to work for Japanese firms, continues today.

The issue was recently brought to the fore by a 2018 South Korean supreme court ruling that ordered Japanese firms to compensate Koreans it used as forced labour.

The decisions drew condemnation from Japan, which argues the dispute was settled in 1965 when diplomatic ties were normalised between the neighbouring countries.

The row has since escalated and has impacted their modern trade relationship, threatening industries such as technology.