New York — President Donald Trump had just announced high-level trade talks between the United States and Japan at a photo op on Wednesday when a reporter shouted a question about the troubled Supreme Court nomination of Brett Kavanaugh.

“They are bringing people out of the woods,” Trump replied, implying Democrats were encouraging women to make false allegations of sexual misconduct. Glancing at Japanese Prime Minister Shinzo Abe seated next to him, the president added with a chuckle: “They could do that to anybody — except Prime Minister Abe, because he’s so pure.”

The awkward joke — which simultaneously minimized the serious allegations against Kavanaugh and unwittingly dragged the leader of an important U.S. ally into the messy affair — neatly illustrated a dynamic that played out here this week as Trump has sought to promote his foreign policy priorities at the U.N. General Assembly.

Time and again, world leaders were reduced to bit players and key foreign policy issues were lost amid the daily — even hourly — spectacle of a president battered and consumed by the twin crises swirling around the White House — Kavanaugh and the fate of Deputy Attorney General Rod Rosenstein, who is scheduled to meet with Trump today in Washington.

Trump made news on foreign affairs — leveling new accusations, with little evidence, against China for attempting to interfere in the U.S. midterm elections and ramping up his rhetoric against Iran over its destabilizing behavior in the Middle East.

And at a wide-ranging, hourlong news conference to wrap up the day that was focused primarily on Kavanaugh, Trump touched on a number of international issues. He claimed to have rejected a meeting with Canadian Prime Minister Justin Trudeau, with whom he is feuding over trade; acknowledged that the pressure of the trade war with China could mean President Xi Jinping is no longer on friendly terms with him; and asserted without evidence that former President Barack Obama was close to starting a war with North Korea.

He also said that U.N. delegates who had laughed audibly early in his speech to the General Assembly on Tuesday were not showing signs of disrespect.

“They weren’t laughing at me,” Trump said. “They were laughing with me.”

But unlike last year, when Trump used his first U.N. address to rally the world in a “maximum pressure” campaign against North Korea, the president struggled this week to stay focused on advancing his global agenda as he and his top advisers frantically sought to contain the deepening political problems in Washington.

Even in the moments where Trump was focused on his foreign policy agenda, such as his speech on Tuesday, analysts said they had difficulty identifying an overarching strategy — other than the vague concept of “American sovereignty,” which appeared aimed at putting other countries on notice that the United States would reject global pacts that the Trump administration finds burdensome.

“He’s basically done a lot of things he wanted to do — pull out of the (Iran nuclear deal) and reach out to North Korea,” said Thomas Wright, a foreign affairs analyst at Brookings Institution. “He sort of declared victory without doing much on them. He ticked through everything and he’s out of ideas. It’s an interesting question of what he’s going to do next, because in his mind all these problems are basically solved.”

Aides had scheduled a busy itinerary for Trump, including bilateral meetings on Wednesday with Israeli Prime Minister Benjamin Netanyahu and British Prime Minister Theresa May, as well as Abe. Trump also chaired a two-hour meeting of the National Security Council to discuss nonproliferation of nuclear weapons.

He called on the members of the council in the order dictated by U.N. customs and cleanly managed a couple of unfamiliar pronunciations — Equatorial Guinea, Côte d’Ivoire. The president remained visibly calm when Bolivian President Evo Morales, a firebrand anti-American former union leader, delivered a lengthy complaint against U.S. policies — concluding by denouncing Trump’s no-tolerance immigration policy.

Morales declared that it is immoral to detain “children in cages.”

Trump didn’t take the bait.

“Thank you, Mr. President,” Trump replied evenly, moving on to the next speaker.

Maybe he was holding his fire for his more formidable adversaries. Within the next hour, Trump had unleashed a broadside on Twitter against Michael Avenatti, the lawyer who represents porn actress Stormy Daniels as well as two women who have lodged allegations against Kavanaugh.

In his tweet, Trump called Avenatti a “third rate lawyer who is good at making false accusations” and a “total lowlife!” The missive scored more retweets and “likes” than any of his other social media messages of the day.

For Abe, the bilateral meeting with Trump was a high-stakes moment. The Japanese president has as diligently as any world leader tried to appeal to Trump’s ego in hopes of winning support on policies — even if Trump has gone against Abe’s wishes on trade and engagement with North Korea.

The two leaders had dined on Sunday night at Trump Tower and celebrated Abe’s 64th birthday, which was two days earlier.

Trump announced that the two nations had agreed to open bilateral trade talks, a high-priority for the president, who has sought to force Tokyo to ease restrictions rice, beef and automarkets — something Japanese leaders have long been resistant to.

Abe thanked Trump for marking his birthday and made a point to praise the “wonderful view” of New York from the president’s penthouse residence in Trump Tower.

But before long, the president had turned his focus to attacking Kavanaugh’s accusers and his Democratic rivals.

“It’s a horrible con game,” Trump said. “I think the people are finding it out. … It’s a disgrace what’s going on.”