HANOI — President Trump spent Wednesday here in Vietnam cozying up to North Korean leader Kim Jong Un over grilled sirloin and chocolate lava cake and reaching for the legacy he wants: the great dealmaker negotiating a historic nuclear arms accord.

But halfway around the globe, an entirely different legacy for Trump was thrust to the fore by his longtime personal attorney and fixer — that of an alleged con man, liar, racist and, ultimately, criminal.

Michael Cohen’s explosive testimony to Congress was not only potentially humiliating for Trump. It also portrayed the president as an unreliable and dishonest man at the very moment he is conducting diplomacy with the world’s most erratic and untrusting dictator. And it propelled Trump’s presidency into greater legal and political peril.

On a day when two events of potentially lasting importance played out simultaneously some 8,300 miles apart, the spectacle in Washington overwhelmed the one in Hanoi.

This reality came into sharp relief as Trump sat down with Kim for a one-on-one chat before dinner here on Wednesday evening. Trump had just boasted of his warm relationship with the North Korean dictator, whom he called “a great leader,” when a reporter asked for his reaction to Cohen’s testimony. Trump did not respond and simply shook his head. But shortly thereafter, that reporter and three others were banned by the White House from covering the dinner because of what Trump press secretary Sarah Sanders called “sensitivities to the shouted questions.”

Cohen’s testimony added to the investigative morass that has consumed Trump’s presidency and served as a reminder of its continual state of turmoil. Although he sat in a hearing room addressing the House Committee on Oversight and Reform, Cohen might as well have been talking directly to his former boss.

“I have fixed things,” he said, “but I am no longer your fixer, Mr. Trump.”

Both politicians avoided the Vietnam War, but only one has apologized for false claims. (Meg Kelly/The Washington Post)

Trump had orchestrated his first full day in Vietnam to project American power. He announced billions of dollars in Vietnamese aircraft purchases, basked in the crowds lining the highways to see him and bantered with flag-waving schoolchildren. The president was meeting with Vietnamese officials when Cohen’s prepared testimony began emerging overnight in Washington, which is 12 hours behind Hanoi.

Trump has complained that the federal investigation involving Cohen, as well as the special counsel probe into Russian interference in the 2016 election, has undercut his image with world leaders. And as he rested in his hotel room Wednesday afternoon ahead of his first interactions with Kim, he took to Twitter to tee off about Cohen.

“Michael Cohen was one of many lawyers who represented me (unfortunately),” Trump wrote. “He had other clients also. He was just disbarred by the State Supreme Court for lying & fraud. He did bad things unrelated to Trump. He is lying in order to reduce his prison time. Using Crooked’s lawyer!”

During the lull, Trump also slammed one of his Democratic critics, Sen. Richard Blumenthal of Connecticut, writing, “I have now spent more time in Vietnam than Da Nang Dick Blumenthal, the third rate Senator from Connecticut (how is Connecticut doing?). His war stories of his heroism in Vietnam were a total fraud — he was never even there. We talked about it today with Vietnamese leaders!”

Trump was referring to Blumenthal’s admission during his 2010 Senate campaign that he misrepresented his military service. He was in the Marine Corps Reserve but did his service in the United States, not in Vietnam. Trump has made up claims about Blumenthal, such as saying the senator brags about his heroism in Danang.

For his part, Trump received deferments from the Vietnam draft, citing bone spurs. In his testimony, Cohen recalled that Trump asked him to manage news coverage of his deferments and once told him, “You think I’m stupid? I wasn’t going to Vietnam.”

Trump had scheduled this week’s two-day summit partially to get away from his domestic troubles, but they nevertheless haunted him here as television networks aired round-the-clock coverage of Cohen’s testimony — an outcome likely to enrage the president, observers and advisers said.

“Nothing else gets to Trump worse than being upstaged,” said Tim O’Brien, author of the biography “Trump Nation: The Art of Being The Donald.”

O’Brien predicted that Cohen’s testimony would get under the president’s skin because it highlighted so many of Trump’s insecurities and perceived weaknesses: his attempts to cover up his academic performance, his lack of service in the Vietnam War, his alleged relations with an adult-film star and the payments made to her, and allegations of racism.

“It’s an epic troll, one of the most epic trolls of Trump’s life,” O’Brien said.

White House officials had hoped Trump would not become distracted overseas by the spectacle of his former attorney and fixer testifying publicly for the first time. But the president’s mind, no matter where he is, often is on domestic issues and his political standing, current and former advisers said.

The episode threatens to weaken America’s standing abroad, according to Ben Rhodes, who served as deputy national security adviser under President Barack Obama.

“The real danger for U.S. credibility and national security is the extent to which the Cohen testimony makes the American president look ridiculous and compromised around the world, which carefully consumes U.S. political news,” Rhodes said. “At home, we can see these things as just another turn in the tabloid drama of the Trump presidency, but the cumulative impact abroad is a steady diminution of America’s standing.”

Rudolph W. Giuliani, Trump’s personal attorney, said before Cohen’s testimony that he did not think the president would pay much attention to it. Other advisers said they were sure that he would — even as they wished he would not.

“He’s too busy for that,” Giuliani said in text messages to The Washington Post. “Cohen’s lying is not unexpected.”

Giuliani said Cohen’s prepared remarks were “pathetic,” adding, “This is a lawyer who [taped] his own client when he claimed he was being loyal. If you believe him you are a fool.”

Trump was urging his team to respond to Cohen even before he touched down in Hanoi on Tuesday night, according to one adviser who spoke on the condition of anonymity to describe internal White House conversations. Republican National Committee officials were instructed to repudiate Cohen’s testimony by pointing to his past lies to Congress, while Sanders attacked Cohen as a “disgraced felon” in a statement this week.

But as Cohen’s testimony continued for hours Wednesday, there was little response from the White House. Senior aides traveling in Hanoi hung out Wednesday evening at the swanky bar in their hotel, where the testimony was playing, but did not comment publicly. Instead, it fell to the RNC and members of Congress to deliver the defense the president has promulgated: that Cohen cannot be trusted on any topic because of his past lies to Congress.

Advisers have said Trump considers Cohen’s move an act of personal betrayal because he considers himself to be the main promoter of Cohen’s career. But it is difficult for Trump to discredit Cohen because of his longtime association with the lawyer and the previous instances in which Trump relied upon Cohen or defended his honor or intelligence.

Former New Jersey governor Chris Christie, an informal Trump adviser, said on ABC News that “there hasn’t been one Republican yet who’s tried to defend the president on the substance. I think that’s something that should be concerning to the White House.”

This is not Trump’s first bout of domestic headaches while on the road. While in Europe last summer, for example, special counsel Robert S. Mueller III indicted Russian agents on charges of attempting to influence the 2016 election in support of Trump.

Just before Trump went to Asia in late 2017, Mueller charged his former campaign chairman, Paul Manafort, as well as his former deputy campaign manager, Rick Gates.

And during his inaugural foreign trip to Saudi Arabia in May 2017, Trump was largely distracted by Mueller, former aides said. The special counsel had just been appointed after Trump fired FBI Director James B. Comey and then bad-mouthed him to senior Russian diplomats in the Oval Office.

This time, it is Cohen’s testimony providing the domestic sideshow to Trump’s turn on the world stage. And with the president under siege back home, he may have been comforted in Hanoi by his traveling entourage.

Spotted at the president’s hotel was Fox News host Sean Hannity, a longtime Trump friend and informal adviser. Just as at the first Trump-Kim summit last year in Singapore, Hannity is scheduled to conduct an interview with the president on Thursday following his meetings with the North Korean autocrat.

Even that does not provide a complete respite, however. One of Cohen’s few other legal clients in recent years, according to court testimony, was Sean Hannity.