WASHINGTON — The United States privately demanded a formal apology from Afghanistan’s national security adviser last week for accusing the Trump administration of selling his country out — and told him he would be cut off from official contacts if he didn’t, several people with direct knowledge of the situation tell NBC News.

The Afghan official, Hamdullah Mohib, refused to apologize, according to those familiar with the incident, returning to Kabul amid deepening uncertainty about the future of the U.S. relationship with Afghanistan and the Trump administration’s delicate peace talks with the Taliban.

It’s unclear whether high-level communications will continue unabated between Afghan President Ashraf Ghani’s government and the U.S., or if so, through what channels. Those with knowledge of the exchange said U.S. officials are no longer in contact with Mohib, who was formerly the Afghan ambassador to Washington.

Although Mohib had been scheduled to visit the White House during his visit to meet with the National Security Council, the U.S. abruptly called off his meeting after learning of his remarks about Khalilzad, a senior Trump administration official said.

“They were personal attacks,” the official said Wednesday. “That’s why the meeting was canceled.”

Mohib also has not spoken in recent days to Zalmay Khalilzad, the U.S. special representative running the peace talks with the Taliban. It was Mohib’s extraordinary public broadside against Khalilzad earlier last week that plunged U.S. ties to Afghanistan to their lowest level since the start of the Trump administration.

The State Department, the White House and the Afghan Embassy in Washington declined to comment on the record about the demand for a formal apology.

For months, frustration has been growing in Afghanistan’s government over being excluded from U.S. talks with the Taliban over the future of the country and the U.S. troop presence there. Until last year, the United States had long insisted on an “Afghan-led, Afghan-owned” peace process in which Afghanistan’s government would be included in any U.S.-Taliban talks.

The Taliban, which considers itself the rightful government in Afghanistan, has long sought direct talks with the U.S. and finally achieved that goal with Khalilzad, who was born in Afghanistan and previously served as U.S. ambassador there.

As desperation grew, Mohib came to Washington and told reporters last Thursday that Afghanistan’s security forces were being “sold out” by the U.S., calling it a “humiliation” that Afghan officials are being excluded from the talks and not kept properly informed about their progress. He suggested that Khalilzad, who’s been discussed as a presidential candidate in Afghanistan, was trying to position himself to take over the country.

"The perception in Afghanistan, people in the government think that perhaps, perhaps all this talk is to create a caretaker government of which he will then become the viceroy," Mohib said.

The Trump administration responded by saying it had summoned Mohib to the State Department so that Undersecretary of State David Hale could personally “reject” the comments and inform Mohib that his comments “only serve to hinder the bilateral relationship and the peace process.”

“To the comments themselves, we don’t believe that they warrant a public response,” State Department spokesman Robert Palladino told reporters last Thursday.

Afghan officials disputed that Mohib had been “summoned” in response to his verbal attack Thursday on Khalilzad, arguing that the meeting had been previously scheduled and that in any regard, it’s a breach of diplomatic protocol for the U.S. to “summon” a national security adviser, rather than a country’s ambassador.

But one U.S. official said that it was actually Mohib’s comments several days earlier, at the Asia Society in New York, that had prompted Hale to schedule the meeting with Mohib to rebuke him. In that appearance on March 11, Mohib avoided attacking Khalilzad directly but criticized the U.S. approach and accused U.S. ally Pakistan of sending terrorists into Afghanistan.

The tensions burst into the open in the meeting between Mohib and Hale, the individuals said, with the Afghan adviser telling the American that he had not been freelancing but rather delivering a message with the full support of Ghani, the Afghan leader.

Mohib urged the Trump administration to be more constructive in responding to Afghanistan’s concerns and warned that if the U.S. kept on the current course, it would lose a key ally, the individuals said.

Foreign diplomats and former U.S. officials said the incident illustrated the mounting desperation in Ghani’s government, particularly ahead of upcoming elections in which his handling of the peace process will be a key issue.

They said that while the Afghan government’s misgivings about the U.S. approach were understandable, Mohib had erred in thinking that such a public rebuke of the U.S. would do anything but make things worse.

“The frustration level I think you can read as being very high or he wouldn’t have done what he did,” said Laurel Miller, the acting U.S. special representative for Afghanistan and Pakistan from 2013 to 2017. “But it can’t be at a breaking point, because the Afghan government remains dependent on support from the United States. They don’t have an exit option from their relationship with the U.S.”

Ghani’s top political rival, former national security adviser Haneef Atmar, blasted Mohib for insulting the U.S. and the thousands of American troops who have died fighting in Afghanistan. In a statement posted to Twitter, he said Mohib had used his visit to the U.S. “as an opportunity to derail the Afghan peace talks with highly inflammatory remarks.”

Yet in Afghanistan, local media have also published photos of what they say are rallies showing hundreds of people supporting Mohib’s stance and his defense of Afghanistan’s right to participate in the peace talks. Cartoons in the Afghan media have depicted Khalilzad whipping Mohib while Pakistan and the Taliban bind his feet.

The U.S. has maintained that even though it’s speaking directly with the Taliban for now, any final deal would require “intra-Afghan” talks in which Afghanistan’s government would participate and sign off.

So far, the talks have focused mainly on the eventual withdrawal of U.S. troops from Afghanistan — the top goal for the Taliban — as well as on Taliban pledges not to let the territory again be used as a haven for extremist groups like al-Qaida to plot attacks against the United States.