The Pakistan representative for Doctors Without Borders, Catherine Moody, declined to comment on the issue, saying the organization now wanted to concentrate “on making the closure as smooth and painless as possible for our staff and the community.”

But an official at the group, who declined to be identified by name because he was not authorized to speak to the news media, said the charity had reapplied for permission to work in Kurram in 2015 but never heard back from the government until last week. He said the group had continued working in Kurram because it believed that under the 2016 memorandum of understanding it was still allowed it to do so, and that it was not breaking the law.

Pakistan’s relationship with foreign aid groups has long been troubled. Diplomats and development workers face severe restrictions on their movements and are sometimes accused of using their work as a cover for espionage.

Aid agencies became particularly suspect in 2011 when Save the Children, which has worked in Pakistan for 37 years, was linked to a Pakistani doctor recruited by the C.I.A. to help in the hunt that led to the killing of Osama bin Laden in the city of Abbottabad.

According to figures released in 2016, Doctors Without Borders has 1,649 staff members across Pakistan.

Since 2007, the charity has been unable to get authorization to send any non-Pakistani staff members into the tribal areas. Its health clinics in the towns of Sadda and Alizai in Kurram have been run by 50 local volunteers and six Ministry of Health employees.

Much of the tribal areas are plagued by poverty, a Taliban insurgency and frequent attacks on militants by American drone aircraft. Years of conflict and displacement have led to the near collapse of the public sector services, including health care. Few doctors and technical workers are prepared to work under such conditions, and residents often must travel far to reach a hospital.