President Trump speaks during a news conference with Spanish Prime Minister Mariano Rajoy in the Rose Garden at the White House. (Jabin Botsford/The Washington Post)

President Trump on Tuesday thanked China for helping rein in North Korea and claimed that international pressure on the ­nuclear-armed outlaw nation is beginning to work, marking a change in tone amid concerns that tensions with Pyongyang are escalating dangerously.

Trump made a point of praising Chinese President Xi Jinping for his efforts to squeeze Chinese ally North Korea economically and diplomatically. In other settings — usually Twitter — Trump has complained about lackluster Chinese cooperation and suggested he could punish China economically if it did not do more.

“I applaud China for breaking off all banking relationships with North Korea, something that people would have thought unthinkable even two months ago,” Trump said. “I want to thank President Xi.”

Although the president repeated a threat of military action, his language was mild by comparison to his branding of North Korean leader Kim Jong Un as “a madman” and his vow last week to “totally destroy” North Korea if necessary to protect the United States or its allies.

Trump also expressed confidence he could solve a decades-long impasse that has bedeviled his predecessors.

During a news conference with Spanish Prime Minister Mariano Rajoy, Sept. 26, President Trump said U.S. military action against North Korea “would be devastating.” (Reuters)

“North Korea is a situation that should have been handled 25 years ago, 20 years ago, 15 years ago, 10 years ago, and five years ago, and it could have been handled much more easily,” Trump said. “Yet various administrations, many administrations — which left me a mess. But I’ll fix the mess.”

The president’s remarks Tuesday appear to reflect an attempt at lowering the temperature after days of heated rhetoric and threats from both sides.

During his first address to the United Nations last week, Trump repeated his dismissive nickname for Kim, “Rocket Man,” and shocked some U.N. diplomats with an open threat of warfare. The possibility of conflict appeared to worsen after the annual diplomatic gathering of the U.N. General Assembly, with the United States launching a symbolic B-1 bomber flight off the North Korean coastline. North Korea’s top diplomat said Monday that Trump had effectively declared war on the rogue nation and that Pyongyang could shoot down a U.S. warplane at will.

Trump’s statements Tuesday closely echo the more diplomatic message being delivered in public and private by top administration officials, who present the threat of military action as part of a coordinated strategy to slow down North Korea’s weapons program and impress upon Kim that these weapons are ultimately a liability. That is the message delivered by Secretary of State Rex Tillerson, national security adviser H.R. McMaster and other officials, who have sought to reassure foreign diplomats after some of Trump’s more florid threats.

Trump spoke during a news conference with Spanish Prime Minister Mariano Rajoy, whose nation is among those that have complied with the Trump administration’s request to downgrade diplomatic ties with North Korea in response to its threats against the United States.

“No one wishes for there to be a war anywhere in the world,” Rajoy said through an interpreter. “We will have to be forceful, and those of us who defend the values of democracy, freedom and human rights have to let North Korea know that it isn’t going anywhere in that direction.”

There have been no public defections from the diplomatic coalition condemning North Korea’s recent escalation in its nuclear and ballistic missile tests, as Trump noted Tuesday.

“I appreciate the United Nations Security Council voting twice, unanimously — 15 to nothing, twice — to adopt hard-hitting resolutions against North Korea,” Trump said.

Just before Trump spoke in the Rose Garden, the Treasury Department announced new sanctions on eight North Korean banks, 26 people in China and three other countries that the Trump administration says are linked to North Korean financial networks.

The penalties come on top of unilateral U.S. sanctions announced last week that are meant to close off the U.S. financial system to Pyongyang and anyone doing business with it, as well as the international import and export restrictions approved since early August.

The Trump administration says there are signs that North Korea is starting to feel the pinch from international pressure, especially with the addition of restrictions on fuel oil and other forms of energy that will affect the ruling elite.

The penalties have not yet worked to deter Kim, who says the United States is bent on war.

“Reversing strategic patience was the first foreign policy decision the Trump administration made,” State Department adviser R.C. Hammond said, referring to the prior policy of waiting Kim out. “There’s no more time to wait while North Korea develops its nuclear capabilities.”

The international pressure campaign involving China was born out of that decision and Trump’s successful summit with Xi at his Mar-a-Lago resort in Florida this year, according to Hammond. “Strategies work when we stick to them,” he said.

Many U.S. officials have concluded that Kim is determined to present the United States with a fait accompli — a nuclear bomb that could be delivered to the mainland United States — before it becomes clear whether he would enter a meaningful negotiation. The Trump administration says it will not tolerate a strategy of nuclear containment against Kim and that the goal of any negotiation would be for Pyongyang to give up its weapons.

China is the linchpin, since Beijing is both North Korea’s main economic partner and traditional protector. Chinese banks and other financial entities have been a lifeline for Kim’s regime, and although China has cut many ties and helped impose international sanctions, U.S. officials say that cracks remain.

The United States has led a pressure campaign to get other nations to stop doing even minimal trade or banking business with North Korea, and to cut or downgrade diplomatic relations with Pyongyang. Those efforts are on top of stricter economic penalties imposed at the United Nations in the past two months.

The State Department announced Tuesday that Tillerson will travel to Beijing this week for talks on North Korea, trade and other issues, including Trump’s visit to China later this year.

State Department spokeswoman Heather Nauert stepped around the question of whether Trump’s name-calling or threats issued via Twitter are a helpful part of the U.S. strategy.

“The president is an effective communicator. I think people know exactly where he stands. We have had a good deal of success in pushing forward with our diplomacy campaign,” Nauert said. “The president has done a strong job” of leading that diplomacy, she said. “Some may not want to give him credit for that.”

Trump said Kim is the aggressor and instigator.

“He’s acting very badly. He’s saying things that should never, ever be said,” the president said. “And we’re replying to those things, but it’s a reply. It’s not an original statement, it’s a reply.”