Ms. Haley’s loyalty to Mr. Trump’s view of the world has been rewarded with a presidential endorsement. “Make sure you order your copy today, or stop by one of her book tour stops to get a copy and say hello. Good luck Nikki!” Mr. Trump wrote on Twitter.

For Ms. Haley, an Indian-American Tea Party activist who became a two-term governor of South Carolina known better as a voice of moderation on racial issues in the South, the reaction to her tweet about Mr. Cummings was a rude reminder of how she risks losing the Trump base when she puts distance between herself and the president.

Mr. Trump, aides said, wanted to respond to her himself, but was talked out of doing it. Instead, Kellyanne Conway, a top adviser who is close with Vice President Mike Pence, shot back at Ms. Haley in a tweet that was sanctioned from the top. “THIS is so unnecessary Trump-PENCE2020,” Ms. Conway wrote, an allusion to the rumors that Ms. Haley had been positioning herself to replace Mr. Pence on the ticket in 2020.

Ms. Haley remains close with the president’s daughter Ivanka and her husband, Jared Kushner, and they warned her to be more careful talking about Mr. Trump, according to two people familiar with the conversation. A spokeswoman for Ms. Haley said she never received such a warning.

Her subsequent pivot can be seen as a recognition of the reality confronting anyone contemplating a future in today’s Republican Party — there is little future after distancing yourself from Mr. Trump.

“It is Trump’s party today and, more likely than not, it will be Trump’s party 10 years from now,” said Kevin Madden, a political strategist and former adviser to Mitt Romney’s presidential campaign. “Trump will cast a long shadow over the party’s profile and will be a litmus test for the party’s most active base voters for years to come.”