The State Department has been a hotbed of resistance to the Trump administration’s policies from the start. About 1,000 staff members signed a cable protesting the temporary ban on visas for visitors from seven predominantly Muslim countries the administration tried to impose in January. There has been a small exodus of senior diplomats, which, combined with the slow pace of appointments, has left the State Department’s headquarters noticeably depleted.
But the tensions between the White House and the diplomatic corps are now flaring up more publicly, and at a more senior level. Mr. Lukens, Mr. Rank, and Ms. Smith have all spent decades in the Foreign Service, rising to posts at or close to the ambassadorial level.
“It’s an extraordinarily unusual situation for the Foreign Service,” said R. Nicholas Burns, who served as undersecretary of state for political affairs in the George W. Bush administration, traditionally the top-ranking position for career diplomats. “They pride themselves on being nonpartisan. You serve each president 150 percent.”
Mr. Burns said the conflicts were more difficult for diplomats at the senior level because their jobs require them to represent or issue statements on behalf of the United States government, sometimes with little guidance from the State Department.
In Mr. Rank’s case, several friends said, he had been directed to present the White House’s rationale for withdrawing from the Paris climate accord to the Chinese government. He told colleagues at a town-hall meeting at the embassy that he could not defend the policy.
Friends said Mr. Rank, who became chargé d’affaires in Beijing in January, was deeply frustrated by the general direction of American policy toward China, but particularly about climate change. He was scheduled to serve until the arrival of Terry Branstad, the former governor of Iowa, who was confirmed as Mr. Trump’s ambassador to China in May.
The climate agreement struck between the Obama administration and the Chinese government in 2014 laid the groundwork for the global agreement signed in Paris. China’s official media has been scorching in its criticism of Mr. Trump’s decision to withdraw from it.
Mr. Rank did not reply to an email seeking comment. Friends said he was on his way back to the United States.
A State Department official, speaking on background because he was not authorized to discuss personnel matters, characterized Mr. Rank’s resignation as a “personal decision.” He declined to say whether it involved climate policy.
A 27-year veteran of the Foreign Service and fluent speaker of Mandarin, Mr. Rank also served in Taiwan, Greece and Mauritius. In recent years, he worked extensively on Afghanistan, serving as the Afghan desk director in Washington and political counselor in Kabul.
“He was a complete pro, extremely well-regarded,” said Daniel F. Feldman, a former special representative for Afghanistan and Pakistan. “In all his years working for me, I never even knew his politics; exactly what you’d hope for from a career Foreign Service officer.”
In Mr. Lukens’ case, the flap was less about principle than a case of mixed signals with the White House. The statement he put out on Sunday, in the wake of the deadly attack on Saturday night, was the kind of statement issued routinely by embassies all over the world.
Mr. Lukens, 53, said in an email that he did not obtain clearance from the State Department for the tweets he posted on Sunday on the embassy’s Twitter account because it was standard practice to express support and condolences to a host country after a terrorist attack.
“I commend the strong leadership of the @MayorofLondon as he leads the city forward after this heinous attack,” Mr. Lukens wrote, adding praise in another post for the “extraordinary” response of the emergency services, law enforcement, and London officials.
Earlier that day, Mr. Trump tweeted, “At least 7 dead and 48 wounded in terror attack and Mayor of London says there is ‘no reason to be alarmed!’” His post misrepresented Mr. Khan, who had told Londoners not to be alarmed by the heavy police presence on the streets after the attack.
On Monday, the president continued his attack against Mr. Khan, the city’s first Muslim mayor, labeling his explanation of his remark about the public not being alarmed as a “pathetic excuse” and accusing the news media of “working hard to sell it.”
Ambassador Smith, who continues to serve in Qatar, could not be reached for comment. Over the weekend, she retweeted a post supporting Mr. Khan from the mayor of Los Angeles, Eric Garcetti.
The divergence between Mr. Lukens and the president drew immediate attention on social media, with some praising the envoy for his grace and humanity and others calling for his head.
Several noted that Mr. Lukens worked for Hillary Clinton when she was secretary of state and played a role in setting up the communications system she used, which allowed her to send and receive email on a private server using a personal email address.
Mr. Lukens, whose father was ambassador to the Republic of Congo, became a familiar figure to the diplomatic press corps as the coordinator of Mrs. Clinton’s overseas trips. He is an affable, low-key diplomat who colleagues said was unlikely to go rogue.
A 28-year veteran of the Foreign Service, Mr. Lukens was named ambassador to Senegal and Guinea-Bissau by President Barack Obama, after tours in Canada, Ivory Coast and China. He became the acting ambassador in London in January after the White House recalled Mr. Obama’s envoy, Matthew Barzun.
Mr. Burns said, “There’s no question he used his best judgment yesterday.” But the State Department official said only that Mr. Lukens’ tweets “speak for themselves.”