Pakistan's military says it wants the US to pull out its troops from the neighboring Afghanistan in order to end a 17-year-old war there.

"We wish that (the) US leaves Afghanistan as friend of the region, not as a failure," Pakistan army spokesman Major-General Asif Ghafoor said during a news conference in the garrison city of Rawalpindi Thursday.

He also said Islamabad supports Washington's outreach to the Taliban which want US troops out of Afghanistan.

Asked what Pakistan could do to help the United States negotiate a political settlement with the Taliban, Ghafoor said, "As much as we can, we will facilitate."

"What the US is expecting from us, and the foreign office is cooperating with, is that somehow they could have these negotiations with them (Taliban)," he added.

The comments came just after US special representative for Afghanistan Zalmay Khalilzad concluded a visit to the Pakistani capital.

Prime Minister Imran Khan, who enjoys the support of Pakistan's army which dominates foreign policy, met Khalilzad earlier in the week and pledged to support a peace process with the Taliban.

Khalilzad, an Afghan-born veteran US diplomat who served as George W. Bush's ambassador to Afghanistan, Iraq and the United Nations, was named by the Trump administration three months ago as a special envoy to negotiate peace.

Khalilzad's visit to Pakistan followed a request from Trump to Prime Minister Khan to assist in moving forward the peace talks.

Contacts have already started between Khalilzad and Taliban representatives with both sides aiming to build a favorable position in advance of any talks.

The Kabul government has already stepped up efforts to convince the Taliban to end the 17-year militancy amid Washington’s failures on the battleground.

At the request of the US, a Taliban office was established in Doha in 2013 to facilitate peace talks. In recent months, Taliban representatives and Khalilzad have discussed the Taliban's conditions to end the war in Afghanistan.

The latest overture came after an exchange of barbed tweets between Trump and Khan last month.

Back then, Khan hit back at Trump following his remarks that Islamabad did not do anything for Washington. Khan, in a series of tweets, defended his country's record in Washington's so-called war on terror. He also accused Trump of making Pakistan a scapegoat to cover Washington’s failure in Afghanistan.

Successive US governments have criticized Pakistan for links with the Taliban and for harboring former al-Qaeda leader Osama bin Laden.

Afghanistan has been gripped by insecurity since the US and its allies invaded the country as part of Washington’s so-called war on terror in 2001. Many parts of the country remain plagued by militancy despite the presence of foreign troops.

US forces have been bogged down there through the presidencies of George W. Bush, Barack Obama and now Trump, with militants now launching attacks on both Pakistan and Afghanistan.