ISLAMABAD, Pakistan — Defense Secretary Chuck Hagel cautioned Pakistan’s prime minister on Monday that if Pakistani regional officials followed through on their threats to block NATO supply lines for the war in Afghanistan, it could jeopardize hundreds of millions of dollars in assistance to the military here, Pentagon officials said.

In response, Prime Minister Nawaz Sharif offered assurances that his government would take action to guarantee the safe passage of American and alliance shipments through the Torkham border crossing between Pakistan and Afghanistan, the officials said.

Mr. Hagel arrived in the Pakistani capital for meetings to shore up one of Washington’s most complicated alliances, meeting with civilian and military officials in an effort to improve a relationship that has often broken down over differences on how to fight terrorist groups within Pakistan.

It was the first visit to Pakistan by an American defense secretary in almost four years. The American officials, who described the session with Mr. Sharif as amicable and constructive, said the talks focused equally on supply lines, counterterrorism, regional security and economic development.