Pakistan’s new leader, stung by President Trump’s threat to crack down on his country for harboring terrorists, insisted on Wednesday that Pakistani military forces had uprooted all the sanctuaries used by Islamic extremists along its rugged frontier with Afghanistan.

“We have regained control of the area,” the prime minister, Shahid Khaqan Abbasi, said in an interview with The New York Times. “There are no sanctuaries anymore. There are none at all. I can categorically state that.”

The prime minister’s blanket denial of Pakistan’s role as a safe haven could augur a turbulent period in its relations with the United States. The success of Mr. Trump’s new strategy for Afghanistan depends on Pakistan playing a more constructive role by depriving militants of the ability to plot and carry out attacks from across the Pakistani border.

“This is a new context,” said President Ashraf Ghani of Afghanistan, in a separate interview with The Times. “It provides a new context for Pakistan to seize the opportunity for engagement.” If the Pakistanis did not do more, he said, “there will be consequences.”