“They’re ruining the game,” Mr. Trump told a rally crowd in Alabama in 2017, describing the players’ protests as “a total disrespect of our heritage,” and urging team owners to fire them.

Even in the White House, professional sports has never been far away. Mr. Trump has outpaced other modern presidents in his recognition of athletes who like him with the Presidential Medal of Freedom. When he bestowed one in September on the former basketball player Jerry West, he reflected on Mr. West’s home state of West Virginia and his own 2016 election victory.

“I shouldn’t say this,” Mr. Trump said, “but I won it by 43 points.”

On Monday, several players for the Washington Nationals made political statements when they visited the White House to celebrate their World Series win. Kurt Suzuki, the team’s catcher, donned a “Make America Great Again” hat and was embraced by the president, who reacted ecstatically to the public gesture of support. When video surfaced on Twitter of the pitcher Stephen Strasburg appearing to avoid shaking Mr. Trump’s hand, the athlete retorted with one of the president’s favorite insults: “#FakeNews.” Several other players skipped the visit, but only one, Sean Doolittle, publicly attributed his decision to his antipathy for the president.

Mr. Trump and his supporters have been more sensitive to his reception at events on the road. Mr. Trump’s World Series appearance was internally seen as the sort of dutiful presidential event he should attend. Trump allies said little about the booing at Nationals Park compared with the reception he received at the New York City bout, which was expected to be more friendly territory: He has been interested in the sport for years. But when Mr. Trump made a split-second decision to go less than two weeks before the event, even the U.F.C. president, Dana White, believed it was short notice.

“We had dinner last Thursday at the White House, and he said ‘I’m coming. I’m coming to New York,’” Mr. White told reporters in recent days. “And I was like ‘Oh, my God! That’s going to be a rough one! Why don’t we do Vegas on the 14th? And New York was the only one that he could do, so he came tonight.”

In the end, the social media fight over whether Mr. Trump had drawn more boos than applause at the event went on much longer than the actual U.F.C. match. The president plays close attention to news coverage of how he is received at those events. Mr. Trump’s elder sons, Eric and Donald Trump Jr., quickly jumped in to attack the president’s critics who posted video suggesting that he had been booed en masse. Other footage, including that shared by the Trumps, showed the crowd cheering.

Both the substance of the fight — and what it meant that a sitting president attended a sport known for its brutal violence — was overshadowed.