A firing contest is seen in this undated photo released by North Korea’s Korean Central News Agency. (Kcna/via Reuters)

Japan and South Korea signed a long-awaited intelligence pact Wednesday, agreeing to share information on threats from North Korea without having to use the United States as an intermediary.

Washington had been urging its two closest allies in Asia to put aside their historical differences so they could cooperate against their common enemy in the region amid stepped-up missile and nuclear tests by the North.

“Even at this moment, North Korea’s Kim Jong Un is obsessed with advancing its nuclear and missile capabilities, including a submarine-launched ballistic missile,” South Korea’s Defense Ministry said in a statement.

The deal, which takes effect immediately, was signed six years to the day after North Korea shelled South Korea’s Yeonpyeong Island near the countries’ western maritime border, killing four people.

The pact, the General Security of Military Information Agreement, was initially to be signed in 2012 but was postponed because of opposition in South Korea, where memories of Japan’s colonial aggression remain strong.

A South Korean protester scuffles with police on Wednesday during a rally against an intelligence-sharing pact with Japan on potential North Korean threats. (Ahn Young-Joon/AP)

Some analysts feared that the deal could be delayed again because of the crisis engulfing South Korean President Park Geun-hye, who is fighting for her political life amid allegations linking her to a corruption and influence-peddling scandal.

But Han Min-koo, the South’s defense minister, and Yasumasa Nagamine, Japan’s ambassador to South Korea, signed the deal in a ceremony in Seoul on Wednesday.

The agreement “will help restrain Pyongyang’s nuclear and missile development programs,” Moon Sang-gyun, spokesman for the South’s Defense Ministry, told reporters.

In Japan, Foreign Minister Fumio Kishida said the deal was “more important than ever as North Korea’s nuclear and missile programs pose a new level of threat.” Several of the missiles that North Korea has fired this year have landed in Japan’s air-defense-identification zone.

The deal would augment allied deterrence and defense by giving both countries expeditious information about North Korean threats from each other’s sensors, said Bruce Klingner, senior research fellow for Northeast Asia at the Heritage Foundation. But the accord is good for the United States as well, he said.

“It will also improve trilateral security cooperation, with the U.S. no longer having to play operator in the middle of phone calls between Seoul and Tokyo,” Klingner said.

The deal remains controversial in Seoul, where opposition parties are strongly against it and want the defense minister dismissed for signing it.

It is also unpopular in Beijing, where China’s Foreign Ministry criticized the deal Wednesday, saying that South Korea and Japan were “locked in a Cold War mind-set.”

“South Korea and Japan . . . have in effect forged a military alliance by signing the pact, strengthening the U.S.-led alliance and further upsetting the strategic balance in Northeast Asia,” Lu Chao, a research fellow at the Liaoning Academy of Social Sciences, told the state-run Chinese newspaper Global Times.

Beijing has become increasingly angry at Seoul’s stronger military cooperation with the United States after North Korea’s nuclear and missile tests this year.

These events helped Seoul overcome its previous reluctance to agree to host a Terminal High-Altitude Area Defense system, commonly known as THAAD, to intercept North Korean missiles. President Xi Jinping’s government in Beijing was infuriated by the decision, viewing it as a way for the United States to keep China’s military in check.

Klingner said Seoul and Tokyo should build on the deal by integrating the South Korean and Japanese programs to improve the likelihood of successfully intercepting North Korean missiles.

“Seoul’s refusal to do so due to historic strains with Japan is like a baseball coach telling his three outfielders not to communicate with each other,” Klingner said. “In baseball, the cost is greater likelihood of a dropped fly ball. In missile defense, the results can be disastrous.”