SEOUL/WASHINGTON (Reuters) - North Korea test-fired a missile that failed immediately after launch early on Thursday, the U.S. and South Korean militaries said, hours after the two countries agreed to step up efforts to counter the North’s nuclear and missile threats.

The missile was believed to be an intermediate-range Musudan and was launched from the western city of Kusong, where the isolated state attempted but failed to launch the same type of missile on Saturday, the U.S. Strategic Command and South Korea’s Office of the Joint Chiefs of Staff said.

The launch came shortly after the United States and South Korea agreed in Washington to bolster military and diplomatic efforts to counter the North’s nuclear and missile programs, which it is pursuing in defiance of U.N. Security Council resolutions.

“We strongly condemn the North’s continued illegal acts of provocation,” the South’s Joint Chiefs of Staff said in a statement.

Japan condemned the launch and said it would make a formal protest to the North through its embassy in Beijing.

The failed missile launch was the eighth attempt in seven months by the North to launch a weapon with a design range of 3,000 km (1,800 miles) that can be fired from road mobile launchers, the two militaries said.

North Korea has been pursuing its nuclear and missile programs at an unprecedented pace this year.

In June, North Korea launched a Musudan missile that flew about 400 km (250 miles), more than half the distance to Japan, a flight that was considered a success by officials and experts in South Korea and the United States.

North Korea said on Thursday that it would continue to launch satellites despite its rival South’s objections, in a statement by its space agency carried by official media.

TRUMP VS CLINTON

Pyongyang says it has a sovereign right to pursue a space program by launching rockets carrying satellites, most recently in February, although Washington and Seoul worry that such launches are long-range missile tests in disguise.

Impoverished North Korea and the rich, democratic South are technically still at war because their 1950-53 conflict ended in a truce, not a peace treaty. The North regularly threatens to destroy the South and its main ally, the United States.

News of the North’s latest ballistic missile launch broke during the third and last U.S. presidential debate in which Republican candidate Donald Trump and his Democratic rival, Hillary Clinton, exchanged sharply contrasting views on U.S. alliances.

Trump said U.S. defense treaties around the world, including with South Korea, had to be renegotiated because “we’re being ripped off by everybody in the world”.

Clinton said Trump wanted to tear up alliances that keep nuclear proliferation in check while she believed alliances make the world and the United States safer.

“I will work with our allies in Asia, in Europe, in the Middle East and elsewhere,” Clinton said.

U.S. Secretary of State John Kerry, speaking before the failed missile launch, said the United States would do “whatever is necessary” to defend itself, South Korea and other allies against North Korea.

Kerry and U.S. Defense Secretary Ash Carter reaffirmed that any attack by North Korea would be defeated, and any use of nuclear weapons “met with an effective and overwhelming response,” a joint statement said.

As part of the military effort, Kerry said the United States would deploy the Terminal High Altitude Area Defense anti-missile system to South Korea “as soon as possible”.

China strongly opposes deployment of the U.S. system, saying it would impinge on its own strategic deterrence.

South Korean Foreign Minister Yun Byung-se, also speaking in Washington before the failed launch, said North Korea was nearing the “final stage of nuclear weaponization” and the allies would mobilize “all tools in the toolkit” to defend themselves.

A U.S. aerospace expert, John Schilling, said this week in a report on the 38 North project that despite the failures, the pace of testing could enable the North to put the Musudan missile into operational service sometime next year.