Secretary of State Mike Pompeo made his first official trip to Pakistan on Wednesday, saying that he hoped to “reset the relationship” with the new government after a period of sharp disagreements between the longtime security allies over Pakistan’s alleged harboring of anti-Afghan militants.

The secretary of state also told reporters that Zalmay Khalilzad, a former U.S. ambassador to Afghanistan and Iraq, was traveling with him from Washington and would join the Trump administration as a special envoy to Afghanistan, with a focus on pursuing reconciliation and peace talks with the Taliban.

It was the first official confirmation of widespread reports that Khalilzad would be named to the position, which has been vacant since President Trump took office. The announcement added emphasis to Pompeo’s message from Washington that settling the Afghan conflict after 17 years is the administration’s top regional priority.

Pompeo’s five-hour visit was greeted with skepticism and indignation in many quarters here, especially because it came just a few days after the Trump administration announced it would suspend $300 million in military support funds to Pakistan as a reprisal for sheltering armed militants who stage attacks on Afghanistan. That was the second major U.S. cut in security assistance to Pakistan this year.

All week, Pakistani commentators denounced the United States as a hectoring bully that seeks to force Pakistan to do its bidding and fails to appreciate its efforts to fight Islamist terrorism. But officials of the new government headed by Prime Minister Imran Khan tried to maintain a cordial tone during the meetings Wednesday, and later pronounced the day a success.

Foreign Minister Shah Mehmood Qureshi said at a news conference Wednesday evening that the discussions with Pompeo, who was accompanied by Gen. Joseph F. Dunford, chairman of the Joint Chiefs of Staff, had “set the stage to reset the environment” for bilateral relations and that he had been invited to Washington to follow up later this month. “We understood what they want, and have also presented what Pakistan expects . . . in a mutually respectful manner,” he said.

 Pompeo, before departing for a longer visit in India, said he was “hopeful” that the talks with Qureshi, Khan and Pakistan’s army chief, Gen. Javed Qamar Bajwa, would lead to improved relations. He said they had discussed the need for a “peaceful resolution” in Afghanistan, but that there was still “a long way to go” on making any firm agreements. 

“We made clear to them and they agreed that it’s time for us to begin to deliver on our joint commitment,” Pompeo said. “There was broad agreement” about the need for “on the ground” actions that will “begin to build confidence and trust.”

Pakistani officials expressed support for recent stepped-up U.S. efforts to seek reconciliation with the Taliban in Afghanistan and settle the 17-year-old conflict peacefully, asserting that it had long been Khan’s wish. Qureshi said they had decided not to mention the military aid cut to maintain a positive atmosphere at the meetings.

Yet up until Wednesday, both Pakistani officials and commentators were fulminating about the sanctions, and a get-acquainted phone call last week between Pompeo and Khan led to an ugly spat when Pakistan heatedly denied a State Department spokesman’s statement that the two had discussed the issue of cross-border attacks.

“The antagonism witnessed now is unprecedented,” Zahid Hussain, a columnist for Dawn newspaper, wrote Wednesday. “Washington’s demand for unquestionable compliance is unacceptable to Pakistan.” Although noting that the two “frenemies” cannot afford to break up, he added, U.S. efforts to “punish” Pakistan with aid cuts and belittle it with “humiliating tweets” would only backfire.

Pompeo told reporters Wednesday that the Islamabad government had been told in advance the sanctions were coming and why. “The rationale for them not getting the money is very clear,” he said. “It’s that we haven’t seen the progress that we need to see from them.”

Pakistan’s priority in foreign policy has always been guarding against aggression by India, its nuclear-armed next-door neighbor. But the American priority in the region today is ending the war in Afghanistan, a long-elusive goal that is showing new promise. U.S. officials are eager to enlist Pakistan’s help in that effort while pressing it to stop cross-border attacks. 

American officials continue to insist that Pakistan is sheltering anti-Afghan militants in its porous border region with Afghanistan. Pakistan has repeatedly denied the charge. Afghan officials accused Pakistan just last month of sending fighters to attack Ghazni, a large Afghan city near the Pakistan border, which was besieged by Taliban forces for four days.

There were widespread reports of wounded and dead fighters being returned to Pakistan for treatment or burial, and foreign diplomats and military officials in Kabul said they had seen indications of that taking place. Pakistani officials have said the victims could have been Pakistani laborers or others caught up in the violence. 

While U.S. officials tried to keep Wednesday’s meetings focused on Afghanistan, Pakistanis continued to grumble about U.S. favoritism toward India and bias against their country. The Trump administration is working on an agreement with India that would give it greater access to defense technology, one of the items on the agenda for Pompeo’s longer, more relaxed visit there beginning Wednesday night. 

Correction: An earlier version of this story incorrectly identified the chairman of the Joint Chiefs of Staff. It has been corrected.