During a news conference last week, Maj. Gen. Asif Ghafoor, the spokesman for Pakistan’s military, warned the United States against taking any unilateral antiterrorism action on Pakistani soil.

Pakistan’s military says it is working to build a fence along the Afghan border to curb infiltration. Officials also say that the estimated 2.7 million Afghan refugees living in Pakistan need to be repatriated because their presence in the country complicates action against Taliban militants. Pakistani officials say fighters from the Taliban and other groups are able to hide in settlement camps by mingling with refugees.

Pakistani officials also insist that Mr. Trump has his figures wrong, taking aim at his claim that the United States had “foolishly” given it $33 billion since 2002.

“About $14 billion of that $33 billion was part of coalition support fund, which was compensation for services rendered,” said Miftah Ismail, an adviser to the prime minister on finance, revenue and economic affairs, in an interview. “Our billings were for $22 billion and we got only $14 billion. So we think the U.S. owes us $8 billion.”

The United States has been withholding $255 million in military aid in hopes of pushing Pakistan to change its behavior. The money was authorized in 2016 and put in escrow in August. In recent days, Trump administration officials have debated whether to announce that Pakistan would not receive the money at all.

Mr. Ismail said the $255 million was a tiny fraction of Pakistan’s gross domestic product. “So, not a great deal of money.”

Pakistani leadership was also comforted by a strong expression of support from China.

Geng Shuang, the spokesman of China’s Foreign Ministry, said during a news conference on Tuesday said that “Pakistan has made great efforts and sacrifices for combating terrorism and made prominent contributions to the cause of international counterterrorism, and the international community should fully recognize this.”